The idea
A PivotTable does one thing: it sorts your rows into buckets and summarises each bucket. You choose the field that decides the bucket, and it builds the table.
Say the source has one row per order line, and you put category in Rows. Excel looks down
the category column, finds the distinct values (Decor, Furniture, Kitchen and so on), and opens
one bucket for each. Every source row goes into the bucket that matches its category. Then, for
each bucket, it applies the summary you chose for Values: add up revenue, or count the lines.
That is the same job as GROUP BY in SQL or groupby in pandas, with one difference: you rebuild
the table by dragging a field instead of rewriting a query.
Figure 1
Twelve order lines fall into six category buckets
| order_id | category | revenue |
|---|---|---|
| 9933 | Decor | 44.99 |
| 9933 | Outdoor | 379.00 |
| 9934 | Furniture | 440.30 |
| 9935 | Textiles | 17.99 |
| 9936 | Kitchen | 11.99 |
| 9937 | Lighting | 756.00 |
| 9937 | Textiles | 28.99 |
| 9938 | Outdoor | 323.94 |
| 9938 | Lighting | 349.00 |
| 9938 | Textiles | 155.94 |
| 9939 | Decor | 17.99 |
| 9940 | Outdoor | 322.15 |
| category | Sum of revenue |
|---|---|
| Decor | 62.98 |
| Furniture | 440.30 |
| Kitchen | 11.99 |
| Lighting | 1105.00 |
| Outdoor | 1025.09 |
| Textiles | 202.92 |
| Grand Total | 2848.28 |
- Twelve order lines, one per row.
categoryrepeats down the column: Outdoor shows up three times, Kitchen once. A PivotTable starts from exactly this kind of long list. categorygoes in Rows. The PivotTable finds the distinct values and opens one bucket for each. Decor has two lines, 44.99 and 17.99. Both fall into the Decor bucket and are added up: 62.98.- Outdoor has three lines: 379.00, 323.94 and 322.15. They are not next to each other in the source, and that does not matter. The bucket only cares about the value in
category. - Every line lands in exactly one bucket, so the buckets together hold the whole table. The Grand Total, 2,848.28, is the sum of all twelve lines, and it also equals the sum of the six rows above it.
Why it exists
In chapter 3 you answered "revenue per category" with SUMIFS: one formula per category, written
once and filled down. That works, but you had to type the list of categories yourself. If a seventh
category appeared in the data, your table would silently miss it.
A PivotTable builds the list of buckets from the data, so nothing is left out and nothing is typed
by hand. It also lets you change the question in seconds. Swap category for channel and you
have revenue per channel. Drag channel into Columns as well and you get a grid of category by
channel. With formulas, each of those is a new table to build; with a PivotTable it is one drag.
How it works under the hood
Four boxes in the PivotTable Fields pane decide the result. In Excel you find them after Insert → PivotTable, with the fields listed above the boxes.
- Rows: one bucket per distinct value, listed down the side.
- Columns: one bucket per distinct value, listed across the top. A field in both Rows and Columns makes a grid, and each cell is the bucket for that pair of values.
- Values: the numbers summarised inside each bucket.
- Filter: rows that never enter any bucket. A filter on
channel = webremoves the other lines before the grouping happens.
The Grand Total at the bottom is not a sum of the displayed numbers. It is the summary run over all rows, with no bucket. For Sum the two are the same, and that is a good check: the buckets must add up to the total.
Two fields make a grid
Put channel in Columns and keep category in Rows. Now every line is sorted twice: by
its category, which picks the row, and by its channel, which picks the column. The cell where
Outdoor meets web holds only the Outdoor lines sold on the web. Cells where no line fits stay
empty, and the row and column totals are the buckets you already had. Two fields is the limit for
reading comfortably; with a third you are usually better off with a filter.
Sum, Count and the other summaries
The summary decides what each bucket tells you. Sum adds up the amounts. Count says how many lines are in the bucket. Average divides the two. The same buckets, three different answers.
Figure 2
Same buckets, three ways to show them
| category | revenue |
|---|---|
| Decor | 62.98 |
| Furniture | 440.30 |
| Kitchen | 11.99 |
| Lighting | 1105.00 |
| Outdoor | 1025.09 |
| Textiles | 202.92 |
| category | lines |
|---|---|
| Decor | 2 |
| Furniture | 1 |
| Kitchen | 1 |
| Lighting | 2 |
| Outdoor | 3 |
| Textiles | 3 |
| category | share |
|---|---|
| Decor | 2.2% |
| Furniture | 15.5% |
| Kitchen | 0.4% |
| Lighting | 38.8% |
| Outdoor | 36.0% |
| Textiles | 7.1% |
- Sum adds up the revenue inside each bucket. This is the table from the last picture.
- Switch the summary to Count and the same buckets answer a different question: how many lines are in each? Outdoor has 3. The revenue amounts are not used at all, only counted.
- "Show values as → % of Grand Total" divides each bucket by the total: Outdoor 1,025.09 ÷ 2,848.28 is 36.0%. Lighting and Outdoor together are three quarters of the day.
Excel picks Count for you in one case you will meet often: when the field in Values contains text, or numbers stored as text. If a column of amounts shows "Count of revenue" instead of "Sum of revenue", the amounts are probably text. Fix the column first (chapter 5), then change the summary.
"Show values as" does not change the buckets, only how each bucket's number is displayed. % of Grand Total divides by the total, % of Column Total divides by the column. Use it when the reader needs shares more than amounts.
The snapshot
A PivotTable does not look at your source cells each time. When you build it, Excel stores a copy of the source, the pivot cache, and draws from that. This is why a pivot on a big table opens fast. It is also why the numbers can be old.
Figure 3
Why a PivotTable can be out of date
- Source table A1:E32 on the sheet
- Pivot cache a snapshot taken when you built or refreshed
- PivotTable what you see in the grid
- When you create a PivotTable, Excel copies the source into a hidden snapshot, the pivot cache, and draws the buckets from the snapshot.
- Now someone corrects a revenue figure in the source. Only the first box changed. The snapshot, and so the PivotTable, still hold the old number.
- PivotTable Analyze → Refresh (or Data → Refresh All) takes a new snapshot and redraws the buckets. Only then do the totals move.
After you edit, add or delete source rows, refresh the PivotTable. If you add rows below the range, the new rows are outside the source and a refresh will not find them. Turn the source into a Table (chapter 6) and the range grows by itself.
Common misconceptions
"A PivotTable updates when I change the data"
A formula does. A PivotTable does not, until you refresh it. If a pivot total looks wrong after
you fixed a figure in the source, refresh before you suspect anything else. A good habit is to
compare the Grand Total with a plain SUM of the source column; if they differ, the pivot is stale
or the source range stops short.
"Count of revenue tells me how many orders there are"
Count counts rows in the bucket, and a row here is an order line, not an order. Order 9938 has three lines, so it adds three to the count. To count orders you need a field with one row per order, or a distinct count. Check by comparing the count with what you can see: the twelve lines above come from only eight orders.
"Sum is always the right summary for a number"
Sum is right for amounts you can add: revenue, units. It is wrong for a price or a rate, because adding three unit prices gives a number that means nothing. Ask what you want each bucket to say. The average price of the lines is a fine answer; the sum of the prices is not.
Check yourself
One question. Answering it ticks this lesson off on the map; it never locks a level.
Not quite. A PivotTable is not linked cell by cell. It reads a snapshot, so it shows the old figure until you refresh.Try another answer.
Right. The snapshot still holds 322.15. After Refresh the Outdoor bucket becomes 379.00 + 323.94 + 400.00 = 1,102.94.
Not quite. Excel shows no error. The PivotTable simply keeps showing the numbers from its last snapshot.Try another answer.
Not quite. It does change: Refresh redraws it from the current source. It just does not do that by itself.Try another answer.
Lesson done: it is ticked on the map.