# GROUPBY

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

groups rows by a field and aggregates 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

```
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, SUM)` | `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/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/groupby