On this page
Kater SQL Functions Windows
KATER__WINDOW_AGGREGATION
A running or trailing aggregate of the value, row by row in the OVER's order.
Family: Windows
Syntax
KATER__WINDOW_AGGREGATION(field, function, frame [, size]) OVER ([PARTITION BY ...] ORDER BY ...)Arguments
Required
| Argument | Description |
|---|---|
field | The value it reads on each row: a field, or a measure, such as orders.sum__amount. |
function | The aggregate to take of the rows in the frame. One of 'count', 'count_distinct', 'min', 'max', 'sum', 'avg'. |
frame | 'running' takes every row from the first to this one. 'trailing' takes this row and the rows before it, size rows in all. One of 'running', 'trailing'. |
Optional
| Argument | Description |
|---|---|
size | How many rows a trailing frame holds, this row included. A running frame does not read it. A whole number. It is 3 when left out. |
Returns
A number. The field menu shows it as the aggregate it takes: a count as a whole number, and the others in the format of the field it reads.
Usage notes
- Write
OVER (ORDER BY ...), and addPARTITION BYto start again for each group. It writes its own frame, so itsOVERtakes noROWSorRANGE. - A running frame compiles to
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, and a trailing frame of size 3 toROWS BETWEEN 2 PRECEDING AND CURRENT ROW. - It counts rows, not calendar periods, so a month with no row is not in the frame.
- A running sum of a measure that cannot be added up across a dimension, such as Revenue across Currency, must start over for each value. Put that dimension in
PARTITION BY.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.order_month AS "Order Month", EVAL(orders.sum__quantity) AS "Units", CUSTOM_CALCULATION( 'window_aggregation__sum__quantity', KATER__WINDOW_AGGREGATION(orders.sum__quantity, 'sum', 'running') OVER (ORDER BY orders.order_month) ) AS "Units So Far"FROM kater_dataset.orders AS ordersWHERE KATER__IS_ON_OR_AFTER(orders.order_date, DATE '2026-05-01')GROUP BY orders.order_monthORDER BY 1| Order Month | Units | Units So Far |
|---|---|---|
| 2026-05-01 | 441 | 441 |
| 2026-06-01 | 403 | 844 |
| 2026-07-01 | 438 | 1,282 |
| 2026-08-01 | 454 | 1,736 |
| 2026-09-01 | 442 | 2,178 |
Compiles to
The call compiles to the same SQL on DuckDB and on Snowflake.
SUM(orders.sum__quantity) OVER (ORDER BY orders.order_month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)