The GROUPBY guide
=GROUPBY(B2:B17, C2:C17, SUM, , , -2) lists each region in B once, adds up its revenue from C, sorts the regions by that total, largest first, and puts a Total row at the bottom. The summary spills into the cells below and updates when the data changes. GROUPBY is in Excel for Microsoft 365 and Excel for the web.
The syntax
=GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array])
- row_fields: what to group by, like the region column, B2:B17.
- values: what to summarise, like the revenue column, C2:C17. Same rows as row_fields.
- function: how to summarise, written as a name without brackets:
SUM,AVERAGE,COUNT,MAX,MIN. - field_headers: whether the ranges start with a header row. Left out, Excel guesses.
- total_depth: 0 for no totals; left out, a grand Total at the bottom.
- sort_order: the column of the result to sort by. 1 is the group names, 2 the totals; a minus sign sorts largest first.
To skip an argument, type nothing between its commas: SUM,,,-2 leaves field_headers and total_depth as they are and sorts by the totals, largest first.
How it works
GROUPBY does what a pivot table with one Rows field and one Values field does, in a formula. Write it in one cell and the result spills: one row per group and the Total under them, two columns wide. Every cell it needs has to be empty, or the formula shows #SPILL!.
Because it's a formula, there's nothing to refresh. Change an amount, or add an order inside the ranges, and the totals and their order update by themselves. A pivot table waits for Refresh.
Headers in the range
If the ranges start at row 1, GROUPBY sees text above numbers, decides row 1 is a header and shows it again on top of the result. When the header is already written above the formula, start the ranges at row 2. To keep a header from the data, start at row 1 and put the formula where its header row can go.
Common mistakes
- SUM in quotes or with brackets.
"SUM"andSUM(C2:C17)both give #VALUE!. The argument is the function itself:SUM. - 2 instead of -2. 2 sorts by the totals smallest first. The minus is what puts the largest on top.
- -1 instead of -2. That sorts by the first column, the names, Z to A.
- 0 as total_depth. The Total row disappears. Leave it empty for the default.
- Ranges of different heights. B2:B17 with C2:C16 gives #VALUE!.
Which versions have GROUPBY?
Excel for Microsoft 365 on Windows and Mac, and Excel for the web. Excel 2024, 2021 and older don't have it and show #NAME?. There, a pivot table gives the same summary, or UNIQUE next to SUMIF for a formula version. GROUPBY's sibling, PIVOTBY, adds a field across the top.
FAQ
- How do I sum by group with one formula in Excel?
- In Microsoft 365, use =GROUPBY(group_range, value_range, SUM). It lists each group once with its total and a Total row, and updates when the data changes.
- How do I sort GROUPBY largest first?
- Give the column to sort by with a minus as the sixth argument: =GROUPBY(B2:B17,C2:C17,SUM,,,-2) sorts by the 2nd column, the totals, largest first.
- How do I remove the Total row from GROUPBY?
- Set total_depth, the fifth argument, to 0: =GROUPBY(B2:B17,C2:C17,SUM,,0).
- Why does GROUPBY show #NAME?
- Your Excel doesn't have it. GROUPBY is in Excel for Microsoft 365 and Excel for the web, not in Excel 2024, 2021 or older. Use a pivot table, or UNIQUE with SUMIF.






































































