Pivoting and Grouping
Create pivot tables with row/column grouping, aggregations, sorting, filtering, totals, drilldown, and slicer integration
Rowsncolumns Spreadsheet ships a full pivot-table authoring experience powered by DuckDB-WASM. Pivots run the same OOXML pivotCacheDefinition / pivotTable round-trip Excel uses, render through the existing CanvasGrid, and accept slicer-driven filtering on top of the regular sort + label-filter pipeline.
Features at a glance
Row / column / value fields with drag-to-reorder and per-field hide
Subtotals + grand totals toggles (per-pivot, separate row + column)
Aggregation functions: sum, count, avg, min, max, var, stddev, median, product
Show Values As —
% of Grand Total,% of Row Total,% of Column Total,Running Total,Rank ↑/Rank ↓Field grouping — date (year / quarter / month / week / day) or numeric (bucket size + optional offset)
Sort — tri-state ↑ / ↓ / none on every field, including value-field sort
Label filter — per-field popover with searchable checkbox list
Top N filter — Top / Bottom × N by any value field
Refresh button + auto-refresh on source mutation
Drilldown — double-click any value cell to see the underlying source rows
Slicer ↔ pivot wiring — slicer selection applies as a label filter to bound pivots
GETPIVOTDATA() — formula-level lookup into a rendered pivot
XLSX round-trip — full
pivotCacheDefinition+pivotTableemission withrefreshOnLoad="1"
Installation
DuckDB-WASM is bundled as a dependency.
Basic setup
usePivot returns the full callback surface; pass the same callbacks to CanvasGrid and to the PivotEditor component:
Authoring a pivot
Programmatic creation
Right-click → "Create pivot table"
The NewPivotTableDialog is the in-app entry. Wire onRequestCreatePivotTable into the right-click context menu and the user picks the source range + target location.
Show Values As
Switch a value field's display mode without changing the underlying aggregate. The transform runs in JS after DuckDB returns the raw sum(...) so any aggregator works.
PERCENT (0.00%) and NUMBER (0) cell formats are auto-derived from the chosen mode and applied to the value + total cells.
Field grouping
Group a date field by period or a numeric field by bucket size. Implemented as a DuckDB EXCLUDE-based SOURCE CTE rewrite — all downstream pivot logic sees the grouped value transparently.
Sort
Tri-state ↑/↓/none. Sort on any row/column field by its labels, or on any value field by its aggregate.
Value-field sort works in both layouts: grouping-only (single value column) AND column-pivoted (multiple colVal_agg(field) columns) — the matcher accepts both alias shapes.
Label filter + Top N
Per-field set filter:
Top N filter (the editor's "Top N filter" toggle does this for you):
The filter is emitted as a subquery against the SOURCE CTE:
Totals toggles
Default is true for all three (Excel default).
Refresh + auto-refresh
Auto-refresh fires when sourceDataVersion bumps — typically when a cell in the pivot's source range changes. The Refresh icon in PivotEditor is a convenience for the manual case.
Drilldown
Double-click any value cell to see the underlying source rows. Wire onDrillDownAtCell to your own modal / sheet / panel:
Slicer integration
Wire the pivot slicer's onFilterPivot callback directly to applySlicerSelectionToPivots:
Slicer selection then routes through the pivot's filter pipeline — checking/unchecking values applies a filterType: "set" filter on the pivot's fieldName. Empty selection clears the filter (shows all values).
GETPIVOTDATA()
Look up a value cell in a rendered pivot from any formula:
The function scans the pivot's row + column header bands for the supplied (field=item) tuples and returns the matching cell. See Formula evaluation for syntax details.
XLSX round-trip
Pivot tables export to a full xl/pivotCache/pivotCacheDefinitionN.xml + xl/pivotTables/pivotTableN.xml pair with refreshOnLoad="1" so Excel rebuilds the cache from the live source on open. Positions, row/column/value fields, aggregation function, sort state, and filter state all round-trip.
Calculated fields / calculated items and the pivot-backed slicer OLAP cube cache export are still deferred.
PivotTable type
Performance notes
DuckDB-WASM runs the PIVOT operator entirely in the browser. Datasets up to a few million rows handle comfortably.
Filter evaluation happens at the SQL layer (
IN (SELECT …)subqueries) — no JS-side row scans for set or Top N filters.Show Values As + value-field sort run as post-aggregation JS transforms — they operate on the already-pivoted result set, not the raw source.
refreshOnLoad="1"in the XLSX export means Excel rebuilds the cache from the live source on open — saved files don't carry stale aggregate values.
Last updated