Excel GROUPBY function
Groups and summarizes data with a single formula: a pivot table that updates by itself. In Spanish Excel it is called AGRUPARPOR.
Syntax
English Excel
=GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array])
Spanish Excel (Mexico)
=AGRUPARPOR(campos_de_fila, valores, función, [encabezados_de_campo], [profundidad_total], [orden_de_clasificación], [matriz_de_filtro])
Spanish Excel (Spain, Latin America)
=AGRUPARPOR(campos_de_fila; valores; función; [encabezados_de_campo]; [profundidad_total]; [orden_de_clasificación]; [matriz_de_filtro])
| Argument | What it is |
|---|---|
| row_fields | The column (or columns) to group by. |
| values | The numbers to summarize. |
| function | SUM, AVERAGE, COUNT, MAX… written without parentheses, or a LAMBDA. |
| field_headersoptional | 0 no headers, 1 has them but hides them, 3 has and shows them. |
| total_depthoptional | 0 no total, 1 total at the bottom, -1 total at the top. |
| sort_orderoptional | The column number to sort by; negative is descending. |
| filter_arrayoptional | A condition to include only some rows. |
Example
GROUPBY(row_fields, values, function) groups repeated values and summarizes them with the function you pass by name: SUM, AVERAGE, COUNT, MAX… It adds a Total row and sorts by the first column. Optional arguments change headers, totals and order.
=GROUPBY(A2:A13,C2:C13,SUM)
Common mistake
Excel 365 only. The function goes without parentheses: GROUPBY(A2:A50,C2:C50,SUM). For rows and columns at once use PIVOTBY.
About Ads
This site uses Google AdSense to display ads. These ads help us keep WebHerramientas completely free. Ads are managed by Google and meet strict security and privacy standards.
Ads help us keep WebHerramientas free for everyone
Practice GROUPBY
Type the formula in the sheet and check it instantly. Spanish or English function names both work. See all lessons
GROUPBY: a pivot table in one formula
GROUPBY(row_fields, values, function) groups repeated values and summarizes them with the function you pass by name: SUM, AVERAGE, COUNT, MAX… It adds a Total row and sorts by the first column. Optional arguments change headers, totals and order.
In E2, summarize the total amount by region with GROUPBY.
| A | B | C | D | E | F | G | H | I | J | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Region | Rep | Amount | Total by region | Average by rep | |||||
| 2 | North | Ana | 12,400.00 | |||||||
| 3 | South | Beto | 8,300.00 | |||||||
| 4 | Central | Carla | 15,600.00 | |||||||
| 5 | North | Dani | 9,100.00 | |||||||
| 6 | South | Ana | 11,200.00 | |||||||
| 7 | Central | Beto | 7,400.00 | |||||||
| 8 | North | Carla | 13,800.00 | |||||||
| 9 | South | Dani | 6,900.00 | |||||||
| 10 | Central | Ana | 10,500.00 | |||||||
| 11 | North | Beto | 8,800.00 | |||||||
| 12 | South | Carla | 14,200.00 | |||||||
| 13 | Central | Dani | 9,700.00 | |||||||
| 14 |
Tip: while typing, click a cell or drag across several to insert their reference. F4 anchors the reference with $.
Frequently asked questions
- What is GROUPBY called in Spanish?
- In Spanish Excel it is AGRUPARPOR. The formula =GROUPBY(A2:A13,C2:C13,SUM) is written =AGRUPARPOR(A2:A13;C2:C13;SUMA) (or with commas in Mexico).
- Why does GROUPBY use semicolons in some Excel versions?
- It depends on regional settings. Where the comma is the decimal mark (Spain, much of South America), Excel separates arguments with semicolons. English Excel and Mexican Spanish Excel use commas.
- What is the most common GROUPBY mistake?
- Excel 365 only. The function goes without parentheses: GROUPBY(A2:A50,C2:C50,SUM). For rows and columns at once use PIVOTBY.