Skip to main content
On this page

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

ArgumentDescription
valueThe number to add up: a measure or an expression.

Returns

The sum from the first row through this row.

Usage notes

  • Write OVER with ORDER BY after the call. PARTITION BY starts 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 orders
WHERE
KATER__IS_ON_OR_AFTER(orders.order_date, DATE '2026-05-01')
GROUP BY
orders.order_month
ORDER BY
1
Order MonthUnitsRunning Units
2026-05-01441441
2026-06-01403844
2026-07-014381,282
2026-08-014541,736
2026-09-014422,178

See also