Kater SQL Functions Calculation context
CUMULATIVE_SHARE
Divides the running total of a value by the sum of all rows, so the last row is 100 percent.
Family: Calculation context
Syntax
CUMULATIVE_SHARE(value) OVER ([PARTITION BY ...] ORDER BY ...)Arguments
| Argument | Description |
|---|---|
value | The number to add up: a measure or an expression. |
Returns
A fraction from 0 to 1. It is null when the sum is zero.
Usage notes
- It is not one row’s share. For each row’s own share of a total, use
SHARE_OF_TOTAL. - Write
OVERwithORDER BYafter the call. WithPARTITION BY, each group reaches 100 percent.
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", CUMULATIVE_SHARE(orders.sum__quantity) OVER (ORDER BY orders.order_month) AS "Share So Far" /* @format percent(1) */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 | Share So Far |
|---|---|---|
| 2026-05-01 | 441 | 20.2% |
| 2026-06-01 | 403 | 38.8% |
| 2026-07-01 | 438 | 58.9% |
| 2026-08-01 | 454 | 79.7% |
| 2026-09-01 | 442 | 100.0% |
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,RUNNING_TOTAL,MOVING_AVERAGE,BY,ACROSS,IGNORE_FILTERS