# Repeat a group total on every row

Shape / table

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

Aggregate over the whole partition or table and put the result on every row, for shares of total and comparisons with the group.

Page: <https://meridian.online/operations/calculate-across-rows/group-total-on-every-row>

## Status

Runs as a SQL step.

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

## The DuckDB step

repeat a group total, and the grand total, on every row

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 order_id, product, amount,
       sum(amount) OVER (PARTITION BY product) AS product_total,
       sum(amount) OVER () AS grand_total,
       round(amount / sum(amount) OVER (PARTITION BY product), 4) AS share_of_product
FROM orders;
SELECT * FROM result ORDER BY order_id;
SELECT CASE WHEN ((SELECT count(*) FROM result) = 10 AND (SELECT map_from_entries(list((product, product_total) ORDER BY product)) FROM (SELECT DISTINCT product, product_total FROM result)) = MAP {'gadget': 140.75, 'gizmo': 319.99, 'widget': 1440.00} AND (SELECT count(DISTINCT grand_total) FROM result) = 1 AND (SELECT any_value(grand_total) FROM result) = 1900.74 AND (SELECT share_of_product FROM result WHERE order_id = 1) = 0.0833 AND (SELECT share_of_product FROM result WHERE order_id = 4) IS NULL) THEN 'as expected' ELSE error('the product totals were not 1440.00, 140.75 and 319.99 on every row, or the grand total 1900.74 was not repeated on all ten') 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).

- Bruin: [`percent_of_total`](https://getbruin.com/docs/bruin/core-concepts/semantic-layer.html) (read 2026-09-27)
- Duckle: [`Window Aggregate`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Distribute total`](https://help.easymorph.com/doku.php?id=transformations:distributetotal) (read 2026-09-27)
- EasyMorph: [`Total/subtotals`](https://help.easymorph.com/doku.php?id=transformations:subtotal) (read 2026-09-27)
- OpenRefine: [`facetCount(choiceValue, s facetExpression, s columnName)`](https://openrefine.org/docs/manual/grelfunctions#other-functions) (read 2026-09-27)
- Polars: [`Expr.over`](https://docs.pola.rs/api/python/stable/reference/expressions/window.html) (read 2026-09-27)
- Tableau Prep: [`Fixed LOD`](https://help.tableau.com/current/prep/en-us/prep_calculations.htm) (read 2026-09-27)
- Tableau Prep: [`{ FIXED }`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- VisiData: [`addcol-aggregate`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/aggregators.py#L412) (read 2026-09-23)
