
PivotTables are one of Excel’s best tools for summarizing data, but they are not always the fastest option. When your source data changes, you may need to refresh the PivotTable, adjust filters, change field settings, or rebuild parts of the report. Excel’s GROUPBY and PIVOTBY functions give you the same summaries as plain formulas. They recalculate instantly, spill into the grid, and can feed other formulas and charts.
In this tutorial, we will show 7 GROUPBY and PIVOTBY tricks that replace your PivotTables. Let’s use these functions instead of building and refreshing PivotTables.
Syntax:
=GROUPBY(row_fields, values, function, [field_headers], [total_depth], [sort_order], [filter_array], [field_relationship])
=PIVOTBY(row_fields, col_fields, values, function, [field_headers], [row_total_depth], [row_sort_order], [col_total_depth], [col_sort_order], [filter_array], [relative_to])
The arguments you’ll use most:
- row_fields / col_fields: the column(s) you want to group by
- values: the column(s) you want to aggregate
- function: SUM, AVERAGE, COUNT, MAX, MIN, MEDIAN, PERCENTOF, a LAMBDA, or several functions combined with HSTACK
- field_headers: 3 shows headers in the output, 0 shows none
- total_depth: 0 no totals, 1 grand total only, 2 grand total plus subtotals. Use negative values (-1, -2) to put totals at the top
- sort_order: column numbers, counted across the row fields and then the values; a negative number sorts descending
- filter_array: a TRUE/FALSE array the same height as your data; only TRUE rows are included
Convert Your Range into a Table:
- Go to the Insert tab >> select Table or press Ctrl + T
- Name it SalesData in the Table Name box on the Table Design tab

Using an Excel Table is especially useful because structured references such as SalesData[Revenue] automatically expand when new records are added.
Trick 1: Create a Multi-Level Summary with GROUPBY
Suppose you want revenue by Region, then by Category within each Region, with subtotals and a grand total, sorted largest first. Instead of creating a PivotTable with two fields in the Rows area, you can give GROUPBY multiple grouping columns.
- To do it, insert the following formula:
=GROUPBY(SalesData[[#All],[Region]:[Category]], SalesData[[#All],[Revenue]], SUM, 3, 2, -3)
How It Works:
- SalesData[[#All],[Region]:[Category]] passes two columns as row fields, which creates the nested grouping
- SUM aggregates revenue
- 3 shows the headers; you must include #All in the references so the first row of each range is the real header
- 2 adds subtotals and a grand total
- -3 sorts by the third column (Revenue) in descending order

Header note: With field_headers set to 3, refer to columns with [#All] (e.g. SalesData[[#All],[Region]]) so the header row is included. Otherwise, use 0 and type your own headers.
The PivotTable Steps It Replaces
- Select any cell in the data and choose Insert >> PivotTable
- Drag Region and Category into Rows
- Drag Revenue into Values and make sure it says Sum of Revenue
- On the Design tab, set Subtotals and Grand Totals as needed
- Right-click a Revenue value and choose Sort >> Sort Largest to Smallest
GROUPBY handles the entire hierarchy with one formula. To get a flat list with no subtotals, change 2 to 0.

Trick 2: Custom Aggregations (Several at Once, or Your Own)
PivotTables offer standard calculations such as Sum, Average, Count, Max, and Min. GROUPBY can go further because its aggregation argument can also contain a custom LAMBDA function.
Several Built-in Aggregations:
=GROUPBY(SalesData[Region], SalesData[Revenue], HSTACK(SUM, AVERAGE, MAX), , 1)
This returns total, average, and largest sale per region in three adjacent columns.

Calculation with LAMBDA:
The function argument also accepts a LAMBDA, so you can aggregate in ways a PivotTable can’t. For example, the spread between the biggest and smallest sale:
=GROUPBY(SalesData[Region], SalesData[Revenue], LAMBDA(x, MAX(x) - MIN(x)), , 1)
Or the number of distinct reps who sold in each region:
=GROUPBY(SalesData[Region], SalesData[Rep], LAMBDA(x, ROWS(UNIQUE(x))), , 1)
Named functions like SUM get an automatic column header. A LAMBDA does not, so type your own header above the spill or wrap the result in VSTACK with a header row.

The PivotTable Steps It Replaces
- Build the PivotTable
- Drag Region into Rows
- Drag Revenue into Values three times
- For each one, click the field >> choose Value Field Settings >> pick Sum, Average, or Max
- Rename each column so the headers make sense
- For distinct counts, tick Add this data to the Data Model when creating the PivotTable and use Distinct Count
- A max-minus-min calculation needs a calculated field or Power Pivot measure
Trick 3: Top-N Groups Without Value Filters
Top-N analysis is common in dashboards. You may want the top five products, customers, regions, or salespeople instead of displaying every category.
Suppose you want the 10 best-selling products, and you want to change the 10 to a different number whenever you like. You can combine GROUPBY with TAKE.
- Put your N in a cell, such as T2, then use:
=TAKE(GROUPBY(SalesData[[#All],[Product]], SalesData[[#All],[Revenue]], SUM, 3, 0, -2), T2+1)
How It Works:
- GROUPBY totals revenue per product and sorts by column 2 (Revenue) in descending order
- Totals are turned off with 0 because a grand total makes no sense in a top-N list
- TAKE keeps the first rows only; the +1 is there because the header row counts as one of the rows
- Type 5 in T2 and you get the top 5

- Now type 10, and you will get the list of top 10 products

The PivotTable Steps It Replaces
- Create the PivotTable
- Drag Product into Rows and Revenue into Values
- Click the dropdown on Row Labels >> choose Value Filters >> select Top 10…
- Set Top, the number of items, and by Sum of Revenue >> click OK
- Repeat the dialog every time you want a different N
Trick 4: Calculate Percent of Total Without “Show Values As”
One of the most useful PivotTable features is Show Values As >> % of Grand Total. GROUPBY can perform the same calculation using the PERCENTOF function.
Suppose you want to calculate each region’s percentage contribution to revenue.
=GROUPBY(SalesData[Region], SalesData[Revenue], HSTACK(SUM, PERCENTOF), , 1)
This shows revenue and its share of the grand total side by side. Format the second column as a percentage with Ctrl + Shift + 5.

If you only need the share, it’s shorter:
=GROUPBY(SalesData[Region], SalesData[Revenue], PERCENTOF, , 1)
In PIVOTBY, the relative_to argument controls what the percentage is measured against. 0 is column totals, 1 is row totals, and 2 is the grand total:
=PIVOTBY(SalesData[Region], SalesData[Category], SalesData[Revenue], PERCENTOF, , 1, 1, 1, 1, , 2)

The PivotTable Steps It Replaces
- Build the PivotTable
- Drag Region into Rows and Revenue into Values
- Drag Revenue into Values a second time
- Right-click the second one >> choose Show Values As >> select % of Grand Total (or % of Column Total, % of Row Total, and so on)
- Rename the column and format it
Trick 5: Filtered Groups Without Slicers or Filter Fields
Another useful GROUPBY feature is its built-in filter_array argument. The filter_array argument lets you limit which source rows count before anything is grouped. You pass any condition that produces TRUE/FALSE per row.
One Condition: Only 2026 Sales
=GROUPBY(SalesData[Region], SalesData[Revenue], SUM, , 1, , YEAR(SalesData[Date]) = 2026)
The empty argument between 1 and the filter simply means “no sort”.

Several Conditions: Hardware Only, On or After a Date Typed in a Cell
=GROUPBY(SalesData[Region], SalesData[Revenue], SUM,, 1, , (SalesData[Category] = "Hardware") * (SalesData[Date] >= AJ2))
Multiplying conditions works as AND. To get OR, add them instead: (cond1) + (cond2) > 0. This is particularly useful when your criteria come from worksheet cells. Changing AJ2 immediately changes the report.

Because the criteria live in ordinary cells, you can wire them up to dropdowns (Data Validation) and get an interactive report with no slicer at all.
The PivotTable Steps It Replaces
- Build the PivotTable
- Drag Category into the Filters area and pick Hardware
- Drag Date into Filters or Rows >> group by Years >> select 2026
- Or insert a Slicer or Timeline from PivotTable Analyze and click through the choices
Trick 6: A Sorted Cross-Tab with PIVOTBY
GROUPBY gives you a list. PIVOTBY gives you a matrix with a second dimension across the top, the classic PivotTable layout. GROUPBY is ideal when you need groups running down rows. PIVOTBY becomes useful when you want categories across both rows and columns.
Region by Category, Regions Sorted by Total Revenue
=PIVOTBY(SalesData[Region], SalesData[Category], SalesData[Revenue], SUM,, 1, -2, 1, 1)
The arguments after SUM mean:
- (blank): field_headers is skipped, so Excel uses its default header handling
- 1: add a grand total row at the bottom
- -2: sort the rows by the first value column (the total) in descending order
- 1: add a grand total column on the right
- 1: sort the column fields A to Z

Month by Month, with No Helper Column
You can use an expression as the column field, so you don’t need to add a Month column to your data:
=PIVOTBY(SalesData[Region], TEXT(SalesData[Date], "yyyy-mm"), SalesData[Revenue], SUM,, 1, -2, 1, 1)
Using yyyy-mm text means the months sort chronologically as plain text.

The PivotTable Steps It Replaces
- Insert a PivotTable
- Drag Region to Rows, Category (or Date) to Columns, and Revenue to Values
- For months, right-click a date >> choose Group >> select Months and Years
- Right-click a value in the Grand Total column >> choose Sort >> select Sort Largest to Smallest
- Open the Design tab >> select Grand Totals to choose where totals appear
Trick 7: A Report That Updates Itself
One of the biggest advantages of formula-based summaries is that the report remains linked directly to the source data. A PivotTable shows stale numbers until someone clicks Refresh (or Data >> Refresh All). A GROUPBY or PIVOTBY report recalculates the moment the source changes.
Suppose the source is an Excel Table called SalesData.
- Create this in the report:
=PIVOTBY(SalesData[Region], SalesData[Category], SalesData[Revenue], SUM, 0, 1, , 1)
This creates a Region × Category sales report with totals.

Because the formula references Excel Table columns, adding new records to SalesData expands those structured references automatically. With Excel’s normal Automatic calculation enabled, the spilled PIVOTBY result recalculates as the source changes.
- For example, if you add:
| Order ID | Date | Region | Category | Product | Rep | Units | Revenue |
|---|---|---|---|---|---|---|---|
| ORD-10127 | 9/27/2026 | Central | Services | Support Plan | Ria | 50 | 7,600 |
| ORD-10128 | 10/14/2025 | Central | Hardware | Router X1 | Ria | 6 | 1,800 |
| ORD-10129 | 10/16/2025 | Central | Hardware | Switch S8 | Mia | 5 | 1,500 |

You do not need the normal PivotTable step of clicking PivotTable Analyze >> Refresh. This makes formula-based summaries particularly convenient for dashboards and continuously growing datasets.
Build on Top of the Spill with the # Operator:
- If the formula is in cell BA1, BA1# always refers to the entire spilled result, however large it is
- For example, the number of regions:
=ROWS(BA1#) - 2
The -2 removes the header row and the grand total row.
Insert Chart:
- Select the spilled range once and insert a chart
- For a chart that keeps growing with the spill, define a name through Formulas >> Name Manager
=SalesData!BA1#
- Use it in the chart’s series, or place the chart on the spill range and let Excel extend it
Keep the Spill Range Clear
- If something blocks the output range, you’ll see a #SPILL! error
- Delete or move whatever is in the way

PivotTable Steps It Replaces
A traditional workflow often involves:
- Convert the source into a Table
- Create a PivotTable
- Add the required fields
- Update the source data
- Right-click the PivotTable >> choose Refresh, or use Data tab >> Refresh All
- If the source range was a fixed range rather than a Table, open PivotTable Analyze >> Change Data Source and extend it
- Re-apply any formatting that Excel dropped when the layout changed (unless Preserve cell formatting on update is ticked)
- Check whether the layout still displays correctly
With GROUPBY or PIVOTBY, the report itself is a dynamic formula.
When to Keep the PivotTable
GROUPBY and PIVOTBY don’t replace everything. Stay with a PivotTable when you need:
- Double-click drill-down to see the underlying rows behind a number
- Slicers and Timelines that click-filter several reports at once
- Automatic date grouping in a click (quarters, years) instead of writing a formula
- Very large datasets or Data Model relationships across multiple tables, where Power Pivot is the better tool
For everything else, such as quick summaries, dashboards, top-N lists, share-of-total tables, and reports that must always be current, a single formula is faster to build, easier to audit, and impossible to forget to refresh.
Conclusion
Now you can apply 7 GROUPBY and PIVOTBY tricks that replace your PivotTables. But remember that PivotTables are still valuable, especially when you want interactive field lists, slicers, drag-and-drop exploration, or reports designed for users who do not want to edit formulas. However, GROUPBY and PIVOTBY make formula-based reporting much more powerful. A single formula can now handle grouping, multiple aggregations, subtotals, Top-N analysis, percentages, filtering, sorting, and two-dimensional summaries. For repeatable worksheet reports and formula-driven dashboards, these functions can eliminate many of the steps traditionally required to create, configure, and refresh a PivotTable.
Get FREE Advanced Excel Exercises with Solutions!

