Excel GROUPBY Function

There are two ways to “excel groupby function”: the quick way you copy and the durable way you understand. This page gives you both. The exact Excel answer is above; below, we build the small mental model that makes the fix stick, so the next variation of the same problem solves itself.

Exact answer

In Excel: use =GROUPBY(group_column, value_column, SUM) — it produces a live grouped summary, a PivotTable that never needs refreshing. Function availability: GROUPBY: Microsoft 365. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.

On this page8

Syntax

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

Arguments

Argumentrequired / optionalDescription
row_fieldsrequiredThe column(s) to group by.
valuesrequiredThe column(s) to aggregate.
functionrequiredThe aggregation — SUM, AVERAGE, COUNT, PERCENTOF and others.
field_headersoptionalWhether the source has headers and whether to show them.
total_depthoptionalGrand and subtotal rows: 0 none, 1 grand total, 2 both.

Related functions

PIVOTBYSUMIFSUNIQUE
▤Annotated stepsExcel
1

Function availability: GROUPBY: Microsoft 365. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.

2

Click a cell on a summary sheet with room for the whole result.

3

Type =GROUPBY( and select the column to group by.

4

Add a comma and select the column of values, then a comma and SUM (or AVERAGE, COUNT).

5

Add total_depth and sort_order arguments if you want totals or a specific order.

Ctrl+CthenCtrl+Shift+V⌘+Cthen⌘+Ctrl+VPaste values · WindowsMac

What this does

GROUPBY aggregates a table by one or more grouping columns and returns the summary as a spilled array. The comparison that matters is against a PivotTable: a pivot must be refreshed after every data change and cannot be referenced reliably by position, while GROUPBY is a formula that recalculates like any other and can be nested inside SORT, FILTER or a chart source. It supports subtotals, custom sort order and a filter array, which covers most of what a simple pivot was used for. Microsoft 365 only, and rolled out gradually — it is absent from every perpetual release. Keep the inputs visible and clearly labelled and the whole thing stays auditable — anyone who opens the file later, including you, can see at a glance exactly what feeds the result and change one assumption without hunting through the formula. Treat “excel groupby function” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected formula shows up while it is still harmless. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That turns a calculation you can defend to a CFO or an auditor into a method you can reuse, explain, and defend when the workbook leaves your screen.

A worked example

Revenue by region from a 5,000-row table: =GROUPBY(A2:A5000, D2:D5000, SUM) spills a two-column summary that updates as rows are added. With a grand total and descending order: =GROUPBY(A2:A5000, D2:D5000, SUM, 3, 1, -2). Two grouping levels: =GROUPBY(A2:B5000, D2:D5000, SUM). GROUPBY makes a grouped summary a formula rather than an object, which removes the refresh step that makes pivots go stale. Check the referenced cells, argument order and result type in your workbook. Start with the worked example before changing an input, then compare the changed result with the calculation you expected. An error value or a result of a different type is a reason to inspect the inputs and arguments.

In Google Sheets

Function availability: GROUPBY: Microsoft 365. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support. The aim was to get you unstuck fast and leave you a little more capable than a copy-paste would. The answer is at the top and the detail above shows why it holds — so the next time a colleague asks, you can answer without reaching for search. For “excel groupby function”, keep the input cells and the result visible while you check the formula in Excel. Follow the worked example and change one input at a time. The steps explain the workbook calculation; this page does not run a live calculator for that task.

Common mistakes

  • Expecting it in Excel 2021 or an older perpetual version, where it returns #NAME?.
  • Passing grouping and value ranges of different heights, which errors.
  • Reaching for it where a real PivotTable is better — drill-down, slicers and manual grouping are all still pivot-only.

Frequently asked questions

Is GROUPBY a replacement for PivotTables?

For simple aggregation, largely yes — and it needs no refresh. Pivots keep the edge for drill-down, slicers and interactive exploration.

Can I group by two columns?

Yes — pass a two-column range as row_fields and you get a nested grouping.

Which versions have it?

Microsoft 365 only, rolled out through the update channels. No perpetual release has it.

Which Excel release does this formula require?

Function availability: GROUPBY: Microsoft 365. These are Microsoft's version markers; earlier perpetual releases do not include these functions. Check the actual product and update channel before using the formula. A marker does not establish an identical Web/Mac workflow or Google Sheets support.