Ravindra BagaleCourses & study guides Track your progress

Excel GROUPBY Function

Chala mitrano — gROUPBY builds a summary table with a formula. Think PivotTable, but it spills as a dynamic array.

Excel 365 needed. GROUPBY is a Microsoft 365 function (rolling channel). Not in Excel 2021/2019 perpetual. Confirm your 365 build if the name is missing.
Fictional sample data. Quick-commerce orders across Pune, Nashik and Manchester. Mixed ₹ and £.

Purpose

Group rows by one or more columns and aggregate values (SUM, COUNT, AVERAGE, and more) — returning a spilled summary array.

Return value

A dynamic array: category labels plus aggregated numbers (and optional totals), spilled into neighbouring empty cells.

Syntax

GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array], [field_relationship])

Arguments

ArgumentRequired?Description
row_fieldsRequiredColumn(s) to group by (city, status, …).
valuesRequiredNumbers to aggregate (amount, qty).
functionRequiredAggregation: SUM, AVERAGE, COUNT, MIN, MAX, etc. (or a LAMBDA).
field_headersOptionalWhether headers are present / should show (see Excel’s enums).
total_depthOptionalGrand / subtotal depth control.
sort_orderOptionalSort groups ascending/descending.
filter_arrayOptionalTRUE/FALSE filter before grouping.

Exact optional enums can vary by 365 build — start with the three required arguments, then add options.

How to use — Why → What → How

Why: Managers ask “sales by city” every Monday. A Pivot works, but a formula summary refreshes with the sheet and can sit beside FILTER/SORT.

What: GROUPBY groups row_fields and runs an aggregate function on values.

How — numbered steps:

  1. Put raw data in a table (Ctrl+T) with City and Amount columns.
  2. Click an empty cell with space below and to the right.
  3. Type =GROUPBY(CityColumn, AmountColumn, SUM)
  4. Press Enter and watch the spill.
  5. Clear blocking cells if you see #SPILL!.

Ravindra Bagale's Tip

Friends, leave empty cells for the spill. GROUPBY needs room, just like UNIQUE and FILTER.

Worked examples

1) Sum amount by city (₹)

Orders for Ananya Joshi’s Pune desk:

CityAmount (₹)
Pune1200
Nashik800
Pune400
Manchester350
Formula: =GROUPBY(A2:A5, B2:B5, SUM)

Result (spill):

CitySum
Manchester350
Nashik800
Pune1600

What it means: Pune rows 1200+400 become 1600; other cities stay single totals. (Sort order may vary by options/build.)

2) Count orders by city

Formula: =GROUPBY(A2:A5, B2:B5, COUNTA)

Result idea: Pune 2, Nashik 1, Manchester 1

What it means: Same groups; function counts instead of summing.

3) Average order value

Formula: =GROUPBY(A2:A5, B2:B5, AVERAGE)

Result idea: Pune average = (1200+400)/2 = 800

4) UK row in £ beside Indian ₹

Keep currencies in separate sheets in real work. For learning, Manchester 350 may be £ — still groups as its own city row.

Formula: =GROUPBY(City, Amount, SUM)

Result: One Manchester total row appears beside Indian cities.

5) Compare with PivotTable

Why try both: PivotTable is click-friendly; GROUPBY is formula-friendly and spills next to other dynamic arrays.

About this data. Four demo rows only. Real ops sheets are longer; the same GROUPBY pattern scales when columns are clean.

Common errors and fixes

#SPILL! — Something blocks the output range. Fix: Clear cells or move the formula.
#NAME? — Function not in your Excel build. Fix: Use Microsoft 365 current channel; otherwise use a PivotTable.
#VALUE! — row_fields / values length mismatch. Fix: Same number of rows.
Weird totals — Text mixed into Amount. Fix: Coerce numbers; clean with VALUE or data cleaning chapter.

PIVOTBY, UNIQUE, SUMIF, SUMIFS, FILTER, PivotTable (feature)

Practice tasks (10)

  1. Task 1. Enter the four-row sample and GROUPBY with SUM.
    Hint: leave spill space empty
  2. Task 2. Change SUM to AVERAGE and note Pune’s average.
    Hint: 800
  3. Task 3. Add a fifth row City=Pune Amount=100; refresh totals.
    Hint: expand ranges or use a Table
  4. Task 4. Use COUNTA to count rows per city.
    Hint: third argument
  5. Task 5. Explain one benefit of GROUPBY vs a static pasted summary.
    Hint: formula updates
  6. Task 6. Force a #SPILL! on purpose, then clear the block.
    Hint: type in the spill zone
  7. Task 7. Build the same summary with a PivotTable and compare numbers.
    Hint: should match SUM
  8. Task 8. Separate £ Manchester onto another sheet and GROUPBY only ₹ cities.
    Hint: clean inputs
  9. Task 9. Write when you would still prefer a PivotTable.
    Hint: click-heavy exploration
  10. Task 10. Bonus: read Microsoft’s optional arguments and try a sort_order if your build supports it.
    Hint: 365 only

Quick quiz

Q1. GROUPBY returns a spilled dynamic array.
Q2. GROUPBY is in Excel 2016 by default.
Q3. The third required argument is usually:
Q4. #SPILL! means:

Answers: Q1=True, Q2=False, Q3=SUM (aggregate), Q4=blocked output.