> For the complete documentation index, see [llms.txt](https://docs.cascade.io/cascade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cascade.io/cascade/functions-and-expressions/building-expressions/guide-to-window-functions.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
