Skip to content

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"])
  • 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 mean grand 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).