# PIVOTBY

database · from excel · excel: differs in detail · no sheets equivalent

groups rows and columns and aggregates the values — excel's argument list; `function` takes an aggregation NAME or selector, not a function reference

## signature

```
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])
```

returns: `array`

## arguments

- row_fields: range — required
- col_fields: range — required
- values: range — required
- function: any — required
- field_headers: number — optional
- row_total_depth: number — optional
- row_sort_order: number — optional
- col_total_depth: number — optional
- col_sort_order: number — optional
- filter_array: range — optional
- relative_to: number — optional

## examples

formula and result, asserted in the engine test suite.

| formula | result | with |
| --- | --- | --- |
| `=PIVOTBY(A1:A3, B1:B3, C1:C3, 1)` | `` | A1=10, A2=20, A3=30, B1=2, B2=4, B3=6, C1=alpha, C2=beta, C3=gamma |

## errors

error values observed from the engine — each with a call that produces it.

| error | produced by |
| --- | --- |
| `#VALUE!` | `=PIVOTBY(1, 2, A1:A3, 4)` |

## related

- [DAVERAGE](https://deepcalc.com/functions/daverage.md) — average of database values matching criteria
- [DCOUNT](https://deepcalc.com/functions/dcount.md) — counts numeric database values matching criteria
- [DCOUNTA](https://deepcalc.com/functions/dcounta.md) — counts non-empty database values matching criteria
- [DGET](https://deepcalc.com/functions/dget.md) — the single database value matching criteria
- [DMAX](https://deepcalc.com/functions/dmax.md) — largest database value matching criteria
- [DMIN](https://deepcalc.com/functions/dmin.md) — smallest database value matching criteria
- [DPRODUCT](https://deepcalc.com/functions/dproduct.md) — product of database values matching criteria
- [DSTDEV](https://deepcalc.com/functions/dstdev.md) — sample standard deviation of matching database values

## navigate

- [all database functions](https://deepcalc.com/functions/database-functions.md)
- [function index](https://deepcalc.com/functions.md) — all 600 functions
- [error values](https://deepcalc.com/errors.md) · [concepts](https://deepcalc.com/concepts.md) · [limits](https://deepcalc.com/limits.md)
- [everything in one file](https://deepcalc.com/llms-full.txt)

source: https://deepcalc.com/functions/pivotby