Excel GROUPBY Function: Step-by-Step Guide
In this article
The GROUPBY function in Excel is a single formula that summarises a column of values by a category and spills the whole summary table into the cells below and to the right. Instead of writing a SUMIF per category, dragging formulas down, or rebuilding a PivotTable every time your data changes, you write one formula such as =GROUPBY(A2:A100, C2:C100, SUM) and Excel returns one row per unique category with the aggregated total beside it. It is a dynamic array function, so the result is live: edit a value, add a row inside the source range, and the summary recalculates on its own. You need a Microsoft 365 version of Excel (Windows or Mac), Excel for the web, or a current version of the Excel mobile app, and a single, clean data range with a header row.
What You'll Need
- A Microsoft 365 subscription copy of Excel, Excel for the web, or a recent Excel mobile app. GROUPBY is not available in Excel 2019, 2021 or any perpetual-licence version, and there is no workaround in those editions — use a PivotTable instead.
- Data laid out in a simple table: one row per record, one header row, no merged cells, and no blank rows splitting the range.
- An idea of the one column you want to group by (the category) and the one or more columns you want aggregated (the values).
- Enough empty cells to the right and below the formula for the result to spill into. If anything blocks that area you will get a #SPILL! error.
Step-by-Step
- Check your version first. Type
=GROin any empty cell. If GROUPBY appears in the autocomplete list, you have it. If the autocomplete shows nothing, you do not, and no formula will work. This one check saves a lot of confusion. - Tidy the source range. Make sure the category column has consistent spellings (“North”, “north” and “ North” count as three separate groups), no merged cells, and no blank rows inside the range. Remove the trailing spaces with TRIM or by using Find & Replace if the groups look duplicated.
- Click an empty cell where you want the top-left corner of the summary to appear. Leave room: a group-by with 12 categories and two aggregations will occupy 12 rows plus a header row and three columns.
- Start the formula with the category range. Type
=GROUPBY(then select the column you want to group on, for exampleA2:A100. Do not include the header cell — include the data rows only. If you do include a header row, that header text simply becomes one of the group labels. - Add a comma and select the value range you want to summarise, for example
C2:C100. It must be the same number of rows as the category range. A mismatch returns a #VALUE! error. - Add a comma and type the aggregation function —
SUM,COUNT,AVERAGE,MAX,MIN,MEDIANand so on, without parentheses. So far:=GROUPBY(A2:A100, C2:C100, SUM). - Close the bracket and press Enter. Excel spills a two-column table: the unique categories on the left, the totals on the right, with a header row auto-generated above them.
- Add a second aggregation if you want it. Place the functions in an array constant:
=GROUPBY(A2:A100, C2:C100, HSTACK(SUM, AVERAGE, COUNT)). Each function becomes its own result column, so you get totals, averages and counts side by side from one formula. - Sort without touching the source data. The fourth argument in the full form is the sort order and the fifth is the sort direction:
=GROUPBY(A2:A100, C2:C100, SUM, , -1)sorts by the group label descending; use2instead of the blank to sort by the second output column (the sum) instead. Directory names change slightly by version, so if the blank argument does not behave as expected, check the function's tooltip as you type. - Add headers and a total row if useful. The sixth argument sets whether to include headers (
1for yes,0for no) and the seventh adds a grand total row from a choice Excel offers in the formula tooltip, such as a total or grand total. Fill these in only if your version lists them; the first three arguments alone are enough to get a working summary. - Aggregate more than one value column. Pass several columns at once:
=GROUPBY(A2:A100, C2:D100, SUM)returns a sum for each value column, so you get one row per category with both totals. - Test that it is live. Change a number in column C and watch the total update. Add a new row inside A2:C100 and it should be picked up automatically. To give yourself room to grow, group on a whole-column reference or convert the range to a table and reference the table columns instead.
Common Mistakes
- Ranges of different heights. The category range and the value range must have exactly the same number of rows. Selecting A2:A100 with C2:C50 fails.
- Wrapping the function in parentheses. Write
SUM, notSUM()— the function name is passed as an argument, not called. - Blocked spill area. If any cell in the output zone contains data, you get #SPILL!. Clear the cells, or move the formula somewhere roomier. Click the error to see Excel highlight the blocking cell.
- Grouping on a helper column full of text numbers. Values stored as text and as numbers look identical but group separately. Convert them to a consistent type first.
- Typing values into the spilled result. The spill range is one formula. Editing a single cell inside it returns #SPILL! or breaks the array; edit the source data instead.
- Assuming it works in older Excel. In Excel 2019 or 2021 the formula is simply unknown and shows #NAME?.
Tips
- Format the source as a table (Insert > Table) and use structured references such as
Sales[Region]so the ranges grow automatically as you add rows. - COUNT counts non-blank numeric cells; COUNTA counts any non-blank cell. For counting text entries, use COUNTA.
- Add a filter argument to hide unneeded groups — for example returning only categories above a threshold — rather than filtering the output by hand. The filter argument accepts an expression over the grouped field.
- Percentages of total are easy: add
PERCENTOFas one of the HSTACK functions and each group's share of the grand total appears as its own column. - If you plan to chart the summary, GROUPBY output is a normal range to a chart, and as long as the row count stays stable the chart keeps working. Big swings in group count can shift the spill and confuse fixed chart ranges, so chart a table-formatted spill area where possible.
- Use
LARGE,SMALLorPERCENTOFas the aggregation where they make sense; the function slot accepts any function that reduces a set of values to one result.
Troubleshooting
#NAME? error. Your Excel version does not have GROUPBY, or the function name is misspelled. Check the version under File > Account and update to the current Microsoft 365 build. If your licence is permanent (2019/2021), switch to a PivotTable: select the data, choose Insert > PivotTable, drag the category to Rows and the value to Values.
#SPILL! error. Something is in the way. Click the error, note the highlighted cells, and clear them. Also check the output is not being placed inside an existing table, which can restrict spilling.
#VALUE! error. Almost always mismatched range sizes. Confirm both ranges start and end on the same rows.
Blank or wrong groups. Look for trailing spaces, inconsistent capitalisation, numbers stored as text, or blank rows in the source. A quick COUNT of the group column against the number of source rows tells you if rows are being missed.
Result will not update. Check calculation is set to Automatic under Formulas > Calculation Options. Press F9 to force a recalculation as a test.
If that did not work, rebuild the formula from just the first three arguments — category range, value range, function — and confirm it spills correctly before adding sort, header or total arguments. Extra arguments are the usual source of puzzling errors.
Frequently Asked Questions
Is GROUPBY the same as a PivotTable?
It solves the same problem in formula form. A PivotTable is easier to explore interactively; GROUPBY is better when you want a live, formula-driven summary that updates without refreshing.
Can I use GROUPBY with more than one grouping column?
Yes. Pass a second category range alongside the first, for example =GROUPBY(HSTACK(A2:A100, B2:B100), C2:C100, SUM), and Excel returns one row per combination of the two.
Why does GROUPBY not exist in my Excel?
It is only in Microsoft 365, Excel for the web and current mobile builds. Older perpetual versions do not receive new functions.
Does the result update when I add rows?
Yes, provided the new rows fall inside the referenced ranges. Use a table or whole-column references to capture additions automatically.
Can I sort the output by the totals instead of the labels?
Yes. Use the sort-order argument with the column number of the result you want to sort by, and -1 for descending.