Skip to main content
On this page

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

ArgumentDescription
valueThe 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 OVER with ORDER BY after the call. With PARTITION 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 orders
WHERE
KATER__IS_ON_OR_AFTER(orders.order_date, DATE '2026-05-01')
GROUP BY
orders.order_month
ORDER BY
1
Order MonthUnitsShare So Far
2026-05-0144120.2%
2026-06-0140338.8%
2026-07-0143858.9%
2026-08-0145479.7%
2026-09-01442100.0%

See also