# Guide to Window Functions

### What are window functions?

Window functions enable users to perform calculations against partitions (i.e. subgroups or sections) of a table. Unlike traditional aggregation functions, window functions partition the table behind the scenes and perform calculations against each partition instead of the entire table.

### Why are window functions helpful?

Let's say that we have a list of populations for each state, broken out by region. If we use `SUM` to add up the population, we'd get the total for the whole column:

{% embed url="<https://datawrapper.dwcdn.net/QBtwx/1/>" %}

**But what if we wanted to sum the population** ***for each region***? In that case, we'd want my new column to contain the total for region each state is in. For that, instead of using `SUM`, we'd use the alternative window function [`SUMBY`](/cascade/functions-and-expressions/functions/aggregate/sumby.md):

{% embed url="<https://datawrapper.dwcdn.net/h4p0c/1/>" %}

Here, we still add up our `Adult Population` but we segment by `Region`. So for each state, we list its region's total population.&#x20;

### Window Functions Available

Many functions are accompanied by their window function equivalents, which perform the same function but on partitioned tables. Generally, window functions take one additional argument, the column on which to partition. Window functions available:

| Function                                                                       | Description                              |
| ------------------------------------------------------------------------------ | ---------------------------------------- |
| [`RANKBY`](/cascade/functions-and-expressions/functions/table/rankby.md)       | Rank values within a group               |
| [`SUMBY`](/cascade/functions-and-expressions/functions/aggregate/sumby.md)     | Total values within a group              |
| [`OFFSETBY`](/cascade/functions-and-expressions/functions/table/offsetby.md)   | Find adjacent values within a group      |
| [`COUNTBY`](/cascade/functions-and-expressions/functions/aggregate/countby.md) | Count the non-null values within a group |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cascade.io/cascade/functions-and-expressions/building-expressions/guide-to-window-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
