Skip to main content
More Menu
Reading ListGanti ke TerangSearch
Reading List

Queue · 0 items

Your reading list is empty. Save articles to read them later.

Start Reading
ESCto close
↑↓to navigate

Excel GROUPBY and PIVOTBY: Deep Dive into New Aggregation Functions

SheetHub3 min
GROUPBY and PIVOTBY are now generally available in Excel for Microsoft 365. These functions let you create aggregated reports with formulas — no Pivot Table drag-and-drop needed. This article goes beyond the basics. Here is how they work under the hood, performance considerations, and patterns for real-world use.

How They Work Under the Hood

GROUPBY creates an in-memory hash table of your data, groups by the specified columns, and applies the aggregation function. Unlike SUMIFS (which scans data once per condition), GROUPBY scans once and groups everything in a single pass. This makes GROUPBY significantly faster than multiple SUMIFS formulas for the same task.

Advanced GROUPBY Patterns

Multiple aggregation functions:
=GROUPBY(tblSales[Region], {tblSales[Amount], tblSales[Amount]}, {SUM, AVERAGE})
This returns total and average sales by region — two aggregations, one formula. Custom aggregation with LAMBDA:
=GROUPBY(tblSales[Region], tblSales[Amount], LAMBDA(x, MEDIAN(x)))
Median sales by region — impossible with Pivot Tables without a workaround. Sorting by aggregated result:
=GROUPBY(tblSales[Region], tblSales[Amount], SUM, , , -2)
Sorts by the aggregation column (column 2) in descending order.

PIVOTBY for Cross-Tabulation

PIVOTBY creates cross-tabulations — one column per unique value:
=PIVOTBY(tblSales[Region], tblSales[Category], tblSales[Amount], SUM)
This creates a table with regions as rows and product categories as columns. Total sales in each cell. With multiple metrics:
=PIVOTBY(tblSales[Region], tblSales[Category], {tblSales[Amount], tblSales[Amount]}, {SUM, COUNT})
Shows both total sales and order count in each cell.

Performance: GROUPBY vs Pivot Table

ScenarioGROUPBYPivot Table
10,000 rows, 5 groupsInstantInstant
100,000 rows, 20 groups2-3 seconds<1 second
500,000 rows, 50 groups8-10 seconds2-3 seconds
Dynamic (data changes often)✅ Auto-updates❌ Needs manual refresh
Formula reference✅ Can be used in other formulas❌ Requires GETPIVOTDATA
Verdict: For datasets under 50,000 rows, GROUPBY is faster in practice because there is no refresh step. For larger datasets, Pivot Tables retain a performance advantage.

Pro Tips

Use Excel Tables as source data. GROUPBY and PIVOTBY work best with structured references from Excel Tables (Ctrl+T). They expand automatically when you add rows. Combine with SORT for control. GROUPBY's built-in sorting is limited. Wrap it with SORT for more options:
=SORT(GROUPBY(tblSales[Region], tblSales[Amount], SUM), 2, -1)
Use PIVOTBY for dynamic dashboards. Unlike Pivot Tables, PIVOTBY formulas can be referenced by charts and other formulas directly.
Topics

Topics in this article

Explore related topics and continue reading similar content.

Share this article

Discussion

Preparing the comments area...

You Might Also Like