# PIVOTBY

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

groups rows and columns and aggregates the values: excel's argument list; `function` is SUM, COUNT, AVERAGE, MAX, MIN or PRODUCT, written as in excel (SUM), as text or as a selector; a LAMBDA is refused

## 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:A4, B1:B4, C1:C4, SUM)` | `` | A1=north, A2=south, A3=north, A4=south, B1=Q1, B2=Q1, B3=Q2, B4=Q2, C1=1, C2=2, C3=3, C4=4 |

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

## navigate

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

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