PivotTable vs GROUPBY and PIVOTBY: Which Should You Use in Excel?
Salman needs sales by city every Monday for Raja Coffee Roasters. Last week he made a PivotTable; this week he added new orders and forgot to press Refresh, so the report was out of date. In Microsoft 365, one formula, =GROUPBY(Orders[City],Orders[Amount],SUM), gives the same table (Pune ₹10,700, total ₹31,540) and updates by itself. A PivotTable still wins for slicers, drill-down and quick dragging of fields.
A PivotTable is a drag-and-drop report that you refresh, with slicers, drill-down, Show Values As and the Data Model. GROUPBY (one axis) and PIVOTBY (rows and columns) are Excel for Microsoft 365 functions that build the same kind of summary as a formula that recalculates automatically and can feed other formulas. Use a PivotTable for exploring and for interactive reports; use GROUPBY or PIVOTBY for summaries that must stay current and sit inside a formula-driven model. In older versions, use SUMIFS by category.
Download the practice file (pivottable-vs-groupby-pivotby.xlsx)
Excel file, 10 KB. It has the sample data used below. All numbers in this workbook are fictional teaching data, not real company figures.
Quick answer
- PivotTable: select the table, Insert > PivotTable, drag City to Rows and Amount to Values. Refresh with Data > Refresh All after the data changes.
- GROUPBY:
=GROUPBY(Orders[City],Orders[Amount],SUM)spills a city list with totals and a grand total. - PIVOTBY:
=PIVOTBY(Orders[City],Orders[Product],Orders[Amount],SUM)adds products across the columns. - Sort, filter and percent of total are arguments: sort_order, filter_array and the PERCENTOF function.
- No Microsoft 365? Use SUMIFS with one row per city; the practice file shows how.
The same summary three ways
| City | Sales (all three methods) | % of total |
|---|---|---|
| Kolhapur | ₹3,900 | 12.4% |
| Nagpur | ₹6,440 | 20.4% |
| Nashik | ₹4,700 | 14.9% |
| Pune | ₹10,700 | 33.9% |
| Solapur | ₹5,800 | 18.4% |
| Total | ₹31,540 | 100.0% |
PivotTable: Rows = City, Values = Sum of Amount
GROUPBY: =GROUPBY(Orders[City],Orders[Amount],SUM)
SUMIFS: =SUMIFS(Orders[Amount],Orders[City],A4) (one row per city)
We verified the SUMIFS numbers by recalculating the practice file. GROUPBY and PIVOTBY are not available in every Excel version, so the practice file keeps them as text on their own sheet, written to the syntax on Microsoft's function pages.
GROUPBY and PIVOTBY formulas
| What you want | Formula |
|---|---|
| Sales by city, with a grand total | =GROUPBY(Orders[City],Orders[Amount],SUM) |
| Sales by city, largest first | =GROUPBY(Orders[City],Orders[Amount],SUM,,,-2) |
| Share of total by city | =GROUPBY(Orders[City],Orders[Amount],PERCENTOF) |
| Only orders with Qty of 3 or more | =GROUPBY(Orders[City],Orders[Amount],SUM,,,,Orders[Qty]>=3) |
| City x Product grid | =PIVOTBY(Orders[City],Orders[Product],Orders[Amount],SUM) |
- The first two arguments are what to group by and what to add up; the third is the function (SUM, AVERAGE, COUNT, PERCENTOF and others).
- Leave arguments empty with commas to skip them: in
SUM,,,-2the -2 is sort_order, meaning sort by the second column (the totals), largest first. - filter_array is a TRUE/FALSE test the same length as the data, such as
Orders[Qty]>=3. - The result spills. Refer to the whole result with the spill operator, for example
=F2#.
Syntax from Microsoft: GROUPBY function and PIVOTBY function. Microsoft's PIVOTBY page notes that, although it can produce similar outputs, PIVOTBY is not directly related to the PivotTable feature.
Differences that decide it
| Point | PivotTable | GROUPBY / PIVOTBY |
|---|---|---|
| Updates | When you refresh (Data > Refresh All) | Automatically, like any formula |
| Version | Excel desktop on Windows and Mac, and Excel for the web | Microsoft's GROUPBY page lists Excel for Microsoft 365; check the function page for your version |
| Building it | Drag fields; no typing | Type a formula; easy to copy and audit |
| Slicers and timelines | Yes | No; use filter_array or a cell with a drop-down list in the formula |
| Percent of total | Show Values As | PERCENTOF function |
| Drill down to the rows | Double-click a value | No; use FILTER for the detail |
| Data Model / many tables | Yes, with Add this data to the Data Model (Windows) | Works on ranges and arrays in the sheet |
| Feeding other formulas | GETPIVOTDATA, or references that move when the layout changes | Reference the spill range with # |
| Formatting | PivotTable styles, kept on refresh | Normal cell formatting and conditional formatting |
Which one to use
- Exploring new data or building an interactive report with slicers: PivotTable.
- A summary inside a model that must always be current (dashboards fed by formulas, monthly packs): GROUPBY or PIVOTBY.
- Sharing with people on Excel 2019 or older: PivotTable or SUMIFS, because the functions will not calculate there.
- Millions of rows or several related tables: PivotTable on the Data Model, or Power Pivot.
Ravindra Bagale's Tip
If a report is read every week, ask: will someone forget to refresh it? If yes, use a formula summary (GROUPBY or SUMIFS). If people need to click and explore, use a PivotTable and put a big 'Refresh All before you read' note next to it.
Ravindra Bagale's Tip – मराठी
Report दर आठवड्याला वाचला जात असेल तर विचारा: कोणी refresh करायला विसरेल का? हो असेल तर formula summary (GROUPBY किंवा SUMIFS) वापरा. लोकांना click करून explore करायचे असेल तर PivotTable वापरा आणि शेजारी मोठी 'वाचण्यापूर्वी Refresh All करा' note ठेवा.
Ravindra Bagale's Tip – हिंदी
अगर report हर हफ्ते पढ़ा जाता है तो पूछिए: क्या कोई refresh करना भूल जाएगा? हाँ, तो formula summary (GROUPBY या SUMIFS) इस्तेमाल कीजिए। अगर लोगों को click करके explore करना है तो PivotTable लगाइए और पास में बड़ा 'पढ़ने से पहले Refresh All करें' note रखिए।
Practice task
- Build a PivotTable from Orders with City in Rows and Sum of Amount in Values. Compare it with the SUMIFS versions sheet.
- Add a new order to the Orders table. Which summaries change straight away and which need a refresh?
- In Microsoft 365, paste the GROUPBY formulas from the practice file and compare the numbers with the SUMIFS versions.
- Change the filter in the fourth formula to orders from Pune only.
- Make the PivotTable show % of Grand Total and compare it with PERCENTOF.
Learn it properly
Course lessons:
- 7.1 Creating a PivotTable
- 7.4 Show Values As
- 9.1 Spill Ranges and the # Operator
- 3.2 SUM, SUMIF and SUMIFS
Related guides: How to Create a PivotTable · PivotTable Slicers and Timelines: Clickable Filters in Excel · Excel vs SQL: Term-by-Term Mapping with Side-by-Side Examples · SUMIF and SUMIFS
Frequently asked questions
Does GROUPBY replace PivotTables?
No. It covers summaries that should update by themselves. PivotTables still offer slicers, drill-down, the Data Model and drag-and-drop layout.
Why do I get #NAME? with GROUPBY?
Your Excel version does not have the function. Use a PivotTable or SUMIFS instead, or open the file in Excel for Microsoft 365.
Can GROUPBY count distinct values?
You can pass a custom LAMBDA as the function, for example LAMBDA(x,ROWS(UNIQUE(x))). A PivotTable can do it with the Data Model's Distinct Count.
Does a PivotTable update automatically?
Not by default. Refresh it with Data > Refresh All, or set it to refresh when the file opens in PivotTable Options.