# Compute a running total

Shape / table

A variant of [Calculate across rows](https://meridian.online/operations/calculate-across-rows).

Accumulate a sum, count, average, minimum or maximum from the first row of the partition down to the current row.

Page: <https://meridian.online/operations/calculate-across-rows/running-total>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

accumulate a sum, count, average, minimum and maximum from the first row to the current one

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
SELECT product, order_id, amount,
       sum(amount) OVER w AS running_sum,
       count(amount) OVER w AS running_count,
       round(avg(amount) OVER w, 4) AS running_avg,
       min(amount) OVER w AS running_min,
       max(amount) OVER w AS running_max
FROM orders
WINDOW w AS (PARTITION BY product ORDER BY order_date, order_id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW);
SELECT * FROM result ORDER BY product, order_id;
SELECT CASE WHEN ((SELECT list(running_sum ORDER BY order_id) FROM result WHERE product = 'widget') = [120.00, 420.00, 930.00, 1440.00] AND (SELECT list(running_count ORDER BY order_id) FROM result WHERE product = 'widget') = [1, 2, 3, 4] AND (SELECT list(running_avg ORDER BY order_id) FROM result WHERE product = 'gadget') = [80.5, 62.875, 46.9167] AND (SELECT list(running_min ORDER BY order_id DESC) FROM result WHERE product = 'gadget') = [15.00, 45.25, 80.50] AND (SELECT list(running_max ORDER BY order_id) FROM result WHERE product = 'widget') = [120.00, 300.00, 510.00, 510.00] AND (SELECT list(running_sum ORDER BY order_id) FROM result WHERE product = 'gizmo') IS NOT DISTINCT FROM [NULL, 99.99, 319.99] AND (SELECT list(running_count ORDER BY order_id) FROM result WHERE product = 'gizmo') = [0, 1, 2]) THEN 'as expected' ELSE error('the running sum, count, average, minimum and maximum from the first row of each product were not the expected values') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Alteryx Designer: [`Running Total`](https://help.alteryx.com/current/en/designer/tools/transform/running-total-tool.html) (read 2026-09-27)
- Bruin: [`running_total`](https://getbruin.com/docs/bruin/core-concepts/semantic-layer.html) (read 2026-09-27)
- Duckle: [`Cumulative`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Running total`](https://help.easymorph.com/doku.php?id=transformations:runningtotal) (read 2026-09-27)
- Polars: [`Expr.cum_count`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.cum_max`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.cum_min`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.cum_prod`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.cum_sum`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.cumulative_eval`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`cum_count`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Polars: [`cum_fold`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Polars: [`cum_reduce`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Polars: [`cum_sum`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Polars: [`cum_sum_horizontal`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Tableau Prep: [`RUNNING_AVG`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`RUNNING_SUM`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`Running Calculation`](https://help.tableau.com/current/prep/en-us/prep_multirow_calculations.htm) (read 2026-09-27)
