# GROUPBY Function

> Group rows by fields and aggregate their values with GROUPBY in TX Sheet Control: SUM or AVERAGE, headers, totals, sort order, filters and the spilled result.

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

---

Group the rows of data by one or more fields and aggregate the values of each group, with a total row. `row_fields` holds the values to group by, `values` the values to aggregate and `function` the aggregation, such as SUM, AVERAGE or COUNT. `field_headers` tells whether the first row holds headers (1 treats it as headers that are not shown), `total_depth` controls the totals (0 for none), `sort_order` sorts by a column of the result (a negative number sorts in descending order), and `filter_array` keeps only the rows with TRUE. The result spills.

### Syntax

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

Category: Lookup. Minimum arguments: 3. Maximum arguments: 8.

Available for supported offline calculation.

### Examples

```text
=GROUPBY({"A";"B";"A"},{2;3;4},SUM)
```

The formula spills A with 6, B with 3 and a Total row with 9.

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:** [GETPIVOTDATA Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/getpivotdata/llms-full.txt)
- **Next:** [GROWTH Function](https://docs.textcontrol.com/tx-sheet-control/reference/formula-functions/growth/llms-full.txt)
