PIVOTBY
Builds a pivot-style summary matrix from row fields, column fields, and values.
PIVOTBY aggregates intersections of row keys and column keys into a dynamic result grid.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=PIVOTBY(row_fields, col_fields, values, function, [field_headers], [row_total_depth], [row_sort_order], [col_total_depth], [col_sort_order], [filter_array], [relative_to])
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
row_fields | range (range) | Required | — |
col_fields | range (range) | Required | — |
values | range (range) | Required | — |
function | any | Required | — |
field_headers | number | Optional | 1 |
row_total_depth | number | Optional | 0 |
row_sort_order | number | Optional | 0 |
col_total_depth | number | Optional | 0 |
col_sort_order | number | Optional | 0 |
filter_array | value | Optional | — |
relative_to | value | Optional | — |
Differences from Excel
A supplied filter array returns #VALUE! in Formualizer. Omitted row_total_depth and col_total_depth default to 0 (no totals) in Formualizer. Excel chooses grand totals and, where possible, subtotals automatically for both axes.
Remarks
row_fields,col_fields, andvaluesmust have matching row counts.- Aggregation accepts text names (for example
"SUM") or numeric codes. - Optional controls include header handling, row/column totals, and sort order.
- Current implementation uses the first column of
col_fieldsandvaluesfor aggregation.
Error cases
- Mismatched row counts and unsupported filter or callable aggregation options return
#VALUE!.
Examples
Sum sales by region and quarter from three columns that include headers.
Formula =PIVOTBY({"Region";"East";"East";"West"},{"Quarter";"Q1";"Q2";"Q1"},{"Sales";10;20;8},"SUM")
Expected result {0, "Q1", "Q2"; "East", 10, 20; "West", 8, 0}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Average the groups, omit totals and sort both the row and column labels.
Formula =PIVOTBY({"East";"East";"West"},{"Q1";"Q2";"Q1"},{10;20;8},"AVERAGE",0,0,1,0,1,,0)
Expected result {"East", 10, 20; "West", 8, 0}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Pivot a single observation into one row and one column group.
Formula =PIVOTBY({"East"},{"Q1"},{10},"SUM",0,0,1,0)
Expected result {"East", 10}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
The grouping and value arrays must align row for row.
Formula =PIVOTBY({"East";"West"},{"Q1"},{10;8},"SUM")
Expected result #VALUE!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Pivot sales by region and quarter
Formula =PIVOTBY(A1:A4,B1:B4,C1:C4,"SUM",3,0,1,0,1)
| A | B | C | |
|---|---|---|---|
| 1 | "Region" | "Quarter" | "Sales" |
| 2 | "East" | "Q1" | 100 |
| 3 | "East" | "Q2" | 150 |
| 4 | "West" | "Q1" | 120 |
Expected result {0, "Q1", "Q2"; "East", 100, 150; "West", 120, 0}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Pivot with totals enabled
Formula =PIVOTBY(A1:A4,B1:B4,C1:C4,"SUM",3,1,1,1,1)
| A | B | C | |
|---|---|---|---|
| 1 | "Dept" | "Month" | "Cost" |
| 2 | "Ops" | "Jan" | 40 |
| 3 | "Ops" | "Feb" | 35 |
| 4 | "Sales" | "Jan" | 55 |
Expected result {0, "Feb", "Jan", "Total"; "Ops", 35, 40, 75; "Sales", 0, 55, 55; "Total", 35, 95, 130}
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
What rows must align in PIVOTBY inputs?
row_fields, col_fields, and values must share the same row count; otherwise PIVOTBY returns #VALUE!.
What value range is currently aggregated?
Current implementation aggregates using the first value column (and first col_fields column for keys), so extra columns are not yet summarized independently.