# GROUPBY

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

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

## signature

```
GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array], [field_relationship])
```

returns: `array`

## arguments

- row_fields: range — required
- values: range — required
- function: any — required
- field_headers: number — optional
- total_depth: number — optional
- sort_order: number — optional
- filter_array: range — optional
- field_relationship: number — optional

## examples

formula and result, asserted in the engine test suite.

| formula | result | with |
| --- | --- | --- |
| `=GROUPBY(R2:R4, S2:S4, 1)` | `north` | R2=north, R3=south, R4=north, S2=100, S3=200, S4=300 |
| `=GROUPBY(R2:R4, S2:S4, 3)` | `north` | R2=north, R3=south, R4=north, S2=100, S3=200, S4=300 |

## errors

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

| error | produced by |
| --- | --- |
| `#VALUE!` | `=GROUPBY(1, A1:A3, 3)` |

## 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/groupby