1. Home
  2. Functions
  3. Array
  4. PIVOTBY

PIVOTBY function

Summarizes data by row and column fields and aggregates the values at each intersection.

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

ArgumentRequiredDescription
row_fieldsRequiredThe column(s) whose values become rows
col_fieldsRequiredThe column(s) whose values become columns
valuesRequiredThe column(s) to aggregate
functionRequiredA function name such as SUM, or a LAMBDA
field_headersOptional0 no headers, 1 headers not shown, 2 no headers but generate them, 3 headers shown
row_total_depthOptional0 no row totals, 1 grand totals (default); negative puts them on top
row_sort_orderOptionalRow field number to sort by, negative for descending
col_total_depthOptional0 no column totals, 1 grand totals (default); negative puts them first
col_sort_orderOptionalColumn field number to sort by, negative for descending
filter_arrayOptionalTRUE/FALSE per row to include
relative_toOptionalFor PERCENTOF: 0 column totals (default), 1 row totals, 2 grand total

How to use PIVOTBY

When PIVOTBY returns more than one value, the result spills into the cells below and to the right. Keep those cells empty, or you get #SPILL!.

PIVOTBY takes 4 required arguments and 7 optional arguments. Type =PIVOTBY( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=PIVOTBY({"a";"b";"a"}, {"x";"x";"y"}, {1;2;3}, SUM)Result 4 by 4 array
Spilled result
ABCD
1xyTotal
2a134
3b22
4Total336

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.