Kater SQL Functions Calculation context
RUNNING_TOTAL
Adds up a value from the first row of the result through each row, in the order you give.
Family: Calculation context
Syntax
RUNNING_TOTAL(value) OVER ([PARTITION BY ...] ORDER BY ...)Arguments
| Argument | Description |
|---|---|
value | The number to add up: a measure or an expression. |
Returns
The sum from the first row through this row.
Usage notes
- Write
OVERwithORDER BYafter the call.PARTITION BYstarts the sum again for each group. - It counts rows, not calendar periods. A month with no rows is not in the result, so the sum steps over it.
- Order by a field that gives each row one place, so the sum is the same on each run.
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", RUNNING_TOTAL(orders.sum__quantity) OVER (ORDER BY orders.order_month) AS "Running Units"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 | Running Units |
|---|---|---|
| 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 |
See also
- Change a measure’s context
- Other functions in Calculation context:
TOTAL,SHARE_OF_TOTAL,VALUE_FOR,CALCULATE_ACROSS,CALCULATE_BY,CALCULATE_PER,RATIO,MOVING_AVERAGE,CUMULATIVE_SHARE,BY,ACROSS,IGNORE_FILTERS