TX Sheet Control

PIVOTBY Function

Function

Group values by row and column fields and aggregate them into a pivot table that spills into the cells next to the formula. row_fields and col_fields hold the values to group by in rows and in columns, values the data to aggregate and function the aggregation, such as SUM or AVERAGE. The optional arguments set the headers (field_headers), the total rows and columns (row_total_depth and col_total_depth, 0 for none), the sort order (row_sort_order and col_sort_order, negative for descending), the rows to include (filter_array, TRUE or FALSE per row) and relative_to. A table that can't spill because the cells are not empty returns #SPILL!.

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)

Category: Lookup. Minimum arguments: 4. Maximum arguments: 11.

Available for supported offline calculation.

Examples

=PIVOTBY({"A";"B";"A"},{2025;2025;2026},{2;3;4},SUM)

The formula spills a table of 4 rows and 4 columns: A and B in the rows, 2025, 2026 and Total in the columns, the sums 2, 4 and 6 for A and 3, empty and 3 for B, and 5, 4 and 9 in the Total row.

Cell and range examples require appropriate input values in the referenced cells. Handle invalid arguments, formula errors and array and spill constraints.

See Also