# PIVOTBY Function

> Group and aggregate values into a spilled pivot table with PIVOTBY in TX Sheet Control: row and column fields, totals, sort order, filters and #SPILL!.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Function
- **Path:** TX Sheet Control > API Reference > Formula Functions > PIVOTBY Function
- **349 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/pivotby/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/pivotby/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/pivotby/llms-full.txt

---

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

```text
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

```text
=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

- [Formulas](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formulas/llms-full.txt)
- [Custom Functions and Formula Data](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/custom-functions/llms-full.txt)

---

## Nearby

- **Previous:** [PI Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/pi/llms-full.txt)
- **Next:** [PMT Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/pmt/llms-full.txt)
