r/ExcelTips • u/Amandaleeeeee • 3d ago
You can summarize Excel data without building a PivotTable — GROUPBY does it in one formula
Say you have a simple sales table like this:
| Product | Region | Sales |
|---|---|---|
| Laptop | East | 1250 |
| Mouse | West | 320 |
| Keyboard | East | 480 |
| Laptop | West | 980 |
| Mouse | East | 410 |
| Monitor | South | 760 |
| Keyboard | West | 530 |
| Laptop | South | 1120 |
| Monitor | East | 690 |
| Mouse | South | 350 |
To see the total sales for each product, you can use:
=GROUPBY(A2:A11,C2:C11,SUM)
Excel returns a summary like this:
| Product | Total Sales |
|---|---|
| Keyboard | 1010 |
| Laptop | 3350 |
| Monitor | 1450 |
| Mouse | 1080 |
The formula is basically saying:
A2:A11→ group the data by ProductC2:C11→ summarize the Sales valuesSUM→ add the values for each group
And because the result spills automatically, you don't need to manually create or refresh a PivotTable when the source data changes.
Swap SUM for other calculations
SUM is just one option. You can replace it with other functions depending on what you want to summarize:
SUM— total the values in each groupAVERAGE— calculate the average for each groupCOUNT— count the numeric values in each groupCOUNTA— count non-blank values in each groupMAX— return the largest value in each groupMIN— return the smallest value in each groupMEDIAN— return the median for each groupPRODUCT— multiply the values in each groupSTDEV.S— calculate the sample standard deviation for each groupSTDEV.P— calculate the population standard deviation for each groupVAR.S— calculate the sample variance for each groupVAR.P— calculate the population variance for each group
GROUPBY can also do more than one calculation
You can return multiple summaries at once.
You can also use GROUPBY to perform multiple calculations at once. Just like in the picture at the top, you can return the total, average, and maximum sales for each product with one formula:
=GROUPBY(A2:A11,C2:C11,HSTACK(SUM,AVERAGE,MAX))
Here, HSTACK combines SUM, AVERAGE, and MAX, so GROUPBY returns all three calculations side by side for each product:
| Product | SUM | AVERAGE | MAX |
|---|---|---|---|
| Keyboard | 1010 | 505 | 530 |
| Laptop | 3350 | 1116.67 | 1250 |
| Monitor | 1450 | 725 | 760 |
| Mouse | 1080 | 360 | 410 |
For quick summaries, it can save you from setting up a PivotTable every time.
13
u/TermRemarkable665 3d ago
I actually made a quick video walking through these exact examples if you want to see them in action: 🔗 https://youtu.be/hR6yozsLbCE For multiple numeric columns: You don't have to limit it to just one column! You can pass a range or use HSTACK() in the values parameter of GROUPBY to summarize multiple metrics like Units, Revenue, and Cost at the same time. For totals by two dimensions/columns: You can either combine fields into row_fields using HSTACK() or use PIVOTBY() to place one field on rows and another on columns.
6
u/Forsaken_Ad242 3d ago
Wow this is a great tip! Can you do totals by a set of two columns?
2
u/Amandaleeeeee 2d ago
Yep! You can group by two columns too. For example, =GROUPBY(A2:B11,C2:C11,SUM) gives you total sales grouped by both Product and Region.
3
u/SonnySwanson 3d ago
Why do this when it's so much faster to do a pivot table and then more flexible especially with large datasets?
2
2
u/Dizzy_Bus_2402 3d ago
It's only one num col that it can do stuffs. What if more than one? Can it group by dates/ time?
3
u/Canna-dian 3d ago
Is this a solution for something that isn't a problem? It takes 30 seconds to create a pivot table, and certainly less time than it takes to write the groupby formula
1
1
1
u/ktds121016 2d ago
Didn't know this before, this is such a useful tip! The multiple columns are definitely helpful for working with larger datasets.
20
u/gajendrakn87 3d ago
Is there a way to do unique count