ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Dynamic arrays
  3. Excel GROUPBY Function: Pivot-Style Summaries With a Formula

Excel GROUPBY Function: Pivot-Style Summaries With a Formula

By ExcelReady Team·Updated November 3, 2026·8 min read

The short answer

GROUPBY groups rows by one or more fields and summarises a value column in a single formula, like a small PivotTable that updates by itself. For example, =GROUPBY(A2:A8,C2:C8,SUM) lists each region with its total sales and a grand total. It is available only in Microsoft 365, so use UNIQUE with SUMIFS in other versions.

Key takeaways

  • The core syntax is =GROUPBY(row_fields, values, function), such as =GROUPBY(A2:A8,C2:C8,SUM).
  • GROUPBY spills a sorted list of groups with their results and adds a grand total row by default.
  • Optional arguments control headers, totals, sort order and a filter, such as only Laptop rows.
  • GROUPBY needs Microsoft 365; Excel 2021 and 2024 show #NAME?.
  • In other versions, SORT(UNIQUE(...)) plus SUMIFS builds the same summary.
On this page+
  1. What is the GROUPBY function?
  2. GROUPBY syntax
  3. How to use GROUPBY: a basic summary
  4. How to sort, filter and remove totals
  5. How to get the same result without GROUPBY
  6. GROUPBY vs a PivotTable
  7. Common GROUPBY errors and fixes
  8. Practise it

The GROUPBY function in Excel builds a pivot-style summary with one formula: it groups your rows by a column, such as Region, and totals another, such as Sales. The result spills into the cells below and updates the moment the data changes, with no Refresh button. This guide covers the syntax, the optional arguments for headers, totals, sorting and filtering, and how to get the same summary in versions of Excel that don't have GROUPBY.

What is the GROUPBY function?#

GROUPBY takes a column to group by, a column of values and a function, then returns one row per group with the result. It is a dynamic array function: you type it in one cell and the answer spills into as many rows as it needs. The guide to dynamic arrays in Excel explains spilling.

Version note: GROUPBY is available in Microsoft 365, including Excel for the web. It is not in Excel 2021 or Excel 2024, where it returns #NAME?. If you share a file with people on those versions, use the fallback later in this guide.

The examples use this sales table in A1:C8:

ABC
1RegionProductSales
2NorthLaptop1,200
3SouthMonitor450
4NorthMonitor300
5EastLaptop1,500
6SouthLaptop900
7EastMonitor600
8NorthLaptop800

GROUPBY syntax#

GROUPBY has three required arguments and five optional ones:

Excel formula
=GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array], [field_relationship])
ArgumentWhat it meansExample
row_fieldsThe column(s) to group byA2:A8
valuesThe column(s) to summariseC2:C8
functionHow to summarise: SUM, AVERAGE, COUNT, MAX…SUM
field_headersWhether the ranges include headers, and whether to show them3
total_depth0 no totals, 1 grand total, 2 grand total and subtotals0
sort_orderColumn number to sort by; negative sorts largest first-2
filter_arrayTRUE/FALSE test that keeps only some rowsB2:B8="Laptop"
field_relationshipHow multiple row fields relate (hierarchy or table)rarely needed

Notice that the function is written as a name, SUM, with no brackets. GROUPBY applies it to each group for you.

How to use GROUPBY: a basic summary#

To total sales by region, type this in an empty cell such as E1:

Excel formula
=GROUPBY(A2:A8,C2:C8,SUM)

The result spills into two columns:

RegionSales
East2,100
North2,300
South1,350
Total5,750

GROUPBY sorts the groups A to Z and adds a Total row by default. Swap SUM for AVERAGE, COUNT, MAX or MIN to change the summary. For example, =GROUPBY(A2:A8,C2:C8,COUNT) counts the sales in each region: 2 for East, 3 for North and 2 for South.

Show the headers#

To keep the column titles, include the header row in both ranges and set field_headers to 3 ("yes, and show them"):

Excel formula
=GROUPBY(A1:A8,C1:C8,SUM,3)

The spilled table now starts with Region and Sales, ready to paste into a report or feed a chart.

How to sort, filter and remove totals#

The optional arguments turn a basic summary into the exact table you need. Leave an argument empty with an extra comma to skip it.

Sort by total, largest first. The totals are the 2nd column of the result, so use -2:

Excel formula
=GROUPBY(A2:A8,C2:C8,SUM,,,-2)

The order becomes North (2,300), East (2,100), South (1,350), with the Total row still at the bottom.

Remove the total row. Set total_depth to 0:

Excel formula
=GROUPBY(A2:A8,C2:C8,SUM,,0)

Keep only some rows. Add a TRUE/FALSE test as the filter_array:

Excel formula
=GROUPBY(A2:A8,C2:C8,SUM,,,,B2:B8="Laptop")

This totals laptop sales only: East 1,500, North 2,000, South 900 and a total of 4,400. The filter works like the FILTER function's include argument.

Group by two fields. Give GROUPBY two adjacent columns as row_fields, such as A2:B8, to group by region and then product. Set total_depth to 2 if you want a subtotal for each region as well as the grand total.

How to get the same result without GROUPBY#

In Excel 2021, Excel 2024 or any version without GROUPBY, two formulas build the same summary. First, list each region once, sorted, in E2:

Excel formula
=SORT(UNIQUE(A2:A8))

This spills East, North and South. The UNIQUE function guide covers how it removes duplicates, and the UNIQUE lesson practises it. Then, in F2, total each one with SUMIFS:

Excel formula
=SUMIFS(C2:C8,A2:A8,E2#)

The E2# refers to the whole spilled list, so SUMIFS returns one total per region: 2,100, 2,300 and 1,350. Add a grand total underneath with SUM if you need one. The SUMIFS function guide explains the argument order.

In Excel 2019 and earlier, which have no UNIQUE, type the region names yourself and fill an ordinary SUMIFS down. The guide to summarising data without a PivotTable walks through all three approaches, and the pivot-style summary lesson lets you build one step by step.

GROUPBY vs a PivotTable#

Both produce the same kind of summary, but they suit different jobs:

GROUPBYPivotTable
Updates when data changesInstantlyAfter Refresh
How you change itEdit the formulaDrag fields
Feeds other formulasEasily, with #Needs GETPIVOTDATA
Excel versionsMicrosoft 365 onlyAll versions
Best forFixed report tablesExploring data

A PivotTable is still the quickest way to explore a new data set: drag a field in, look, drag it out. GROUPBY is better for a report table that should always be current, or one that other formulas depend on. The guide to PivotTables for beginners covers the PivotTable side, and PivotTable vs SUMIFS compares the formula approach in more depth.

GROUPBY also has a sibling, PIVOTBY, which adds a column field to make a cross-tab, such as regions down the side and products across the top. It is also a Microsoft 365 function.

Common GROUPBY errors and fixes#

Most GROUPBY problems are about spilling, versions or range sizes:

  1. #NAME? Your Excel version doesn't have GROUPBY. Use SORT, UNIQUE and SUMIFS instead.
  2. #SPILL! Something is in the way of the result. Clear the cells below and to the right of the formula.
  3. An error from mismatched ranges. The row_fields and values ranges must have the same number of rows. Make them start and end on the same rows.
  4. Headers counted as a group. You included the header row but didn't set field_headers. Start both ranges at row 2, or set field_headers to 3.
  5. The function has brackets. Write SUM, not SUM(), in the third argument.

Practise it#

GROUPBY is the newest way to do something every analyst does: total a column by group. Try the SUMIFS exercise on this page, then practise pivot-style summaries in a live spreadsheet and the modern Excel functions lesson, which covers the dynamic array functions behind this approach. Each lesson checks your formula instantly.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

GROUPBY would list every region with its total. Build one row of that summary by hand: click F2 and use SUMIFS to total the Sales in C2:C8 for the region in E2.

fx
ABCDEFG
1
Region
Product
Sales
Region
Total sales
2
North
Laptop
1200
East
3
South
Monitor
450
4
North
Monitor
300
5
East
Laptop
1500
6
South
Laptop
900
7
East
Monitor
600
8
North
Laptop
800
9
10
11

Tip: SUMIFS puts the range to add first: C2:C8. Then the Region column, A2:A8, and the region in E2.

Practise this in a lesson

LessonPivot-style summary with formulasBuild a summary table like a pivot table with formulas: a sorted UNIQUE list of categories, then SUMIFS and COUNTIFS filled down beside it.LessonUNIQUE: list and count distinct valuesPull a clean list of distinct regions or customers with UNIQUE, then count them with COUNTA.LessonModern Excel: XMATCH, SORTBY, TEXTSPLIT and spill references (A2#)Split names with TEXTSPLIT, find positions with XMATCH, sort by another column with SORTBY, and refer to a whole spilled result with A2#.Function guideUNIQUEList distinct values with Excel's UNIQUE, count them with COUNTA, or find items that appear only once. Examples plus a live exercise.Function guideSUMIFSTotal values that meet several conditions with SUMIFS. Examples by region, month and number range, common errors, and live practice.

Frequently asked questions

What does GROUPBY do in Excel?

+

GROUPBY groups the rows of a table by one or more columns and applies a function such as SUM, AVERAGE or COUNT to a value column. It spills the result as a small summary table with a grand total.

Which versions of Excel have GROUPBY?

+

GROUPBY is available in Microsoft 365, including Excel for the web. It is not in Excel 2021 or Excel 2024, where the formula shows #NAME?.

Is GROUPBY better than a PivotTable?

+

It is better when you want a summary that updates instantly and feeds other formulas. A PivotTable is better for exploring data by dragging fields, and it works in every version of Excel.

How do I sort GROUPBY results by the total?

+

Use the sort_order argument with the column number of the values. =GROUPBY(A2:A8,C2:C8,SUM,,,-2) sorts by the second column, the totals, from largest to smallest.

How do I remove the total row from GROUPBY?

+

Set total_depth, the fifth argument, to 0: =GROUPBY(A2:A8,C2:C8,SUM,,0). Use 2 to show subtotals as well when you group by more than one field.

Sources

  • UNIQUE function - Microsoft Support
  • SUMIFS function - Microsoft Support
  • Dynamic array formulas and spilled array behavior - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What is the GROUPBY function?
  2. GROUPBY syntax
  3. How to use GROUPBY: a basic summary
  4. How to sort, filter and remove totals
  5. How to get the same result without GROUPBY
  6. GROUPBY vs a PivotTable
  7. Common GROUPBY errors and fixes
  8. Practise it

Keep reading

Data tools· 6 min read

Summarize Data Without a Pivot Table

To summarize data without a pivot table, build the summary with formulas. Put =SORT(UNIQUE(B2:B9)) in F2 to list each category once, then =SUMIFS(D2:D9,B2:B9,F2#) in G2 to total each one. Use COUNTIFS or AVERAGEIFS for counts and averages. The summary updates as soon as the data changes, with no refresh.

Data tools· 5 min read

Pivot Tables in Excel: A Beginner's Guide

A pivot table summarizes a long table in a few clicks, without formulas. Click a cell in your data, choose Insert > PivotTable, and click OK to put it on a new sheet. Then drag fields into Rows, Columns and Values: Region in Rows and Sales in Values gives total sales for each region.

Dynamic arrays· 7 min read

The UNIQUE Function in Excel

The UNIQUE function returns each different value in a range once, in the order it first appears: =UNIQUE(C2:C9). Type it in one cell and the results spill into the cells below. Wrap it in COUNTA to count distinct values, or in SORT to put them in order. UNIQUE needs Excel 2021, Excel 2024 or Microsoft 365.

More on dynamic arrays

  • LAMBDA Function in Excel: Write Your Own Functions
  • LET Function in Excel: Name the Parts of a Formula
  • List All Matching Values in One Cell
  • How to Randomize a List in Excel With SORTBY
  • How to Reverse the Order of a List in Excel
  • The SEQUENCE Function in Excel
All dynamic arrays articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free