Table of Contents
GROUPBY summarizes values by row categories; PIVOTBY summarizes them across row and column categories. They are useful when you want a formula-driven summary that recalculates with its source. They do not create an Excel PivotTable object.
Check that your Excel version and update channel recognize the functions before building a report around them. A workbook shared with someone whose Excel does not support them may not calculate correctly.
Start with a small sales example
Suppose row 1 contains the headers Region, Product, and Sales, with four data rows in A2:C5:
| Region | Product | Sales |
|---|---|---|
| East | Pen | 10 |
| West | Pen | 20 |
| East | Book | 30 |
| West | Book | 40 |
Enter the summary formula in an empty area with room for its results to spill. The examples below exclude the source headers and explicitly turn off totals to keep the output easy to check.
GROUPBY: total sales for each region

=GROUPBY(A2:A5,C2:C5,SUM,0,0)This groups the region labels and sums their corresponding sales. East totals 40 and West totals 60.
The required arguments are the grouping range, values range, and aggregation function. Suitable aggregations include SUM and AVERAGE. COUNT counts numeric values, so it is not always a substitute for counting records with text or blanks.
PIVOTBY: compare regions and products

=PIVOTBY(A2:A5,B2:B5,C2:C5,SUM,0,0,,0)Here, regions form the rows and products form the columns. The East/Book intersection is 30; West/Pen is 20. The empty argument preserves the position of the row-sort option while the following zero disables column totals.
Optional arguments that need care
Both functions provide controls beyond the basic examples:
- Headers:
field_headersis not a simple show/hide switch. Use 0 for input without headers, 1 for input with headers that are not shown, 2 to generate headers, and 3 for input headers that are shown. Omission uses automatic detection. - Totals: 0 disables totals, 1 requests grand totals, and 2 adds subtotals where multiple grouping fields support them. Negative settings place totals before details.
- Sorting: a sort number refers to a field or value column. A negative number reverses that column's sort. Do not assume omitting it preserves source row order.
- Filtering: the Boolean filter array must align with the source rows.
For GROUPBY, field_relationship defaults to a hierarchy (0); table mode is 1. For PIVOTBY, relative_to matters for two-argument aggregations such as PERCENTOF, rather than converting an ordinary SUM into percentages automatically.
Use Microsoft's GROUPBY reference and PIVOTBY reference when adding those advanced options.
Choose the summary method that fits
Use these formulas for compact, visible calculations. Use a conventional PivotTable when you prefer a field-list interface, slicers, timelines, or interactive report layouts. See creating PivotTables and building a PivotTable dashboard.
Check that numeric amounts are stored as numbers and category labels are consistent. If the source will grow, use an Excel Table with structured references; a fixed range such as A2:A5 will not automatically include rows added beyond it.
Reader Comments 0
Sign in with email or Google to join the discussion.