Grand totals & subtotals
Every parent node in the tree is already a subtotal — the engine aggregates each group at every
level as it builds the roll-up. Turn on grandTotal and it also prepends one synthetic “Total”
row that aggregates across all rows. Both are computed in the engine (a grand total is a true
re-aggregation of the source, not a sum of the visible subtotals), so calculated measures on the
total row see it as their context.
from dash_tensor_grid import TensorGrid, build_grid
payload = build_grid(sales, { "rows": ["region", "country"], "measures": {"revenue": "sum", "cost": "sum", "qty": "sum"}, "formats": {"revenue": "currency:USD", "cost": "currency:USD"}, "grand_total": True, # prepend the synthetic "Total" row})TensorGrid(id="grid", row_data=payload["row_data"], column_defs=payload["column_defs"])<TensorGrid data={data} rows={['region', 'country']} measures={{ revenue: 'sum', cost: 'sum', qty: 'sum' }} formats={{ revenue: '$0,0', cost: '$0,0' }} grandTotal/>;<TensorGrid :data="data" :rows="['region', 'country']" :measures="{ revenue: 'sum', cost: 'sum', qty: 'sum' }" :formats="{ revenue: '$0,0', cost: '$0,0' }" grand-total/>mountTensorGrid(el, { data, rows: ['region', 'country'], measures: { revenue: 'sum', cost: 'sum', qty: 'sum' }, formats: { revenue: '$0,0', cost: '$0,0' }, grandTotal: true,});- Subtotals are automatic. Every non-leaf row is a subtotal of its children at that group level — there is no flag to turn on; expanding a group reveals the breakdown beneath its subtotal.
- The total row is re-aggregated from source, so a
meangrand total is the mean of the raw rows, not the mean of the subtotals. The engine marks it (_isGrandTotal) and the component renders it distinctly (a header-band emphasis). - Excluded from conditional-format domains. The synthetic total is left out of a column’s faceted min/max so it can’t flatten a color scale or data bar.
- Pivots differ. In a cross-tab the grand-total column is on by default
(
grand_total), column subtotals too (col_subtotals); a grand-total row is opt-in (row_grand_total).