Sub topic 6
Calculating values with Summarize by
This chapter covers the Values section of the pivot table editor and its Summarize by setting. It assumes you can already create a pivot table and place fields in Rows and Columns. You should also know what sum, count and average mean.
What the Values section does
Rows and Columns decide how the data is grouped. Values decide what is calculated inside each group. Each field you add to Values gets its own Summarize by function. That function collapses all the source rows in a group into one number.
Take a sales table with columns Date, Region, Rep, Product, Revenue and Units. If Region is in Rows and Revenue is in Values with SUM, each region row shows the total of all Revenue cells whose Region matches. The pivot table never changes the source data. It only reads it.
You can add the same field to Values more than once. For example, add Revenue three times and set one copy to SUM, one to AVERAGE and one to COUNT. Each copy becomes its own column, so you can compare total, typical size and number of deals side by side.
The Summarize by functions
Click a field in Values and open the Summarize by drop-down. These are the options:
| Function | What it returns | Typical use |
|---|---|---|
| SUM | Total of the numeric values | Revenue, units, cost |
| COUNTA | Number of non-empty cells | How many records exist |
| COUNT | Number of numeric cells | How many numbers were entered |
| COUNTUNIQUE | Number of distinct values | Distinct customers per region |
| AVERAGE | Mean of the numeric values | Average deal size |
| MAX | Largest value | Biggest sale |
| MIN | Smallest value | Smallest sale |
| MEDIAN | Middle value | Typical value when outliers distort the mean |
| PRODUCT | Product of the values | Compounded growth factors |
| STDEV, STDEVP | Sample or population standard deviation | Spread of values |
| VAR, VARP | Sample or population variance | Spread of values |
| CUSTOM | A formula you write | Combining summarized fields |
Most analysis uses SUM, COUNTA, COUNTUNIQUE and AVERAGE. Choose the function by the question you are asking, not by what the editor suggests first.
Why the default is sometimes wrong
When you add a field to Values, Sheets picks a default. Numeric fields usually default to SUM. Text fields default to COUNTA. The default depends on the cell contents, so it can be wrong in a way that is easy to miss.
If a Revenue column contains numbers stored as text, such as "1,200" with a leading apostrophe or imported text, Sheets cannot add them. The field then defaults to COUNTA, and the pivot table shows how many cells there are instead of a total. The fix is in the source data. Convert the column to real numbers, then re-add the field or change Summarize by to SUM.
COUNT, COUNTA and COUNTUNIQUE
These three functions give different answers on the same field, and mixing them up is a common source of wrong counts.
- COUNTA counts every non-empty cell, whether it holds text, a number or a date.
- COUNT counts only cells that hold numbers. Dates count because Sheets stores them as numbers, but text does not.
- COUNTUNIQUE counts each distinct value once.
Suppose Region is in Rows and Rep is in Values. COUNTA of Rep gives the number of sales rows per region. COUNTUNIQUE of Rep gives the number of different people who made those sales. If Dana made four sales in the West, COUNTA adds four and COUNTUNIQUE adds one.
Blank cells matter here. COUNTA ignores blanks, so a record with an empty Rep cell does not appear in the count. If you want to count records no matter what, summarize a field that is always filled in, such as an order ID.
Worked example
This example uses a small sales table in a sheet named Sales, with a header row in row 1.
| Date | Region | Rep | Product | Revenue | Units |
|---|---|---|---|---|---|
| 2026-01-05 | West | Dana | Widget | 1200 | 10 |
| 2026-01-09 | West | Dana | Gadget | 800 | 4 |
| 2026-01-12 | East | Omar | Widget | 600 | 5 |
| 2026-02-03 | West | Priya | Widget | 1500 | 12 |
| 2026-02-14 | East | Omar | Gadget | 900 | 6 |
| 2026-02-20 | East | Lena | Gadget | 400 | 2 |
Build the pivot table like this:
- Select the data and choose Insert, then Pivot table. Put it in a new sheet named Pivot.
- Under Rows, add Region.
- Under Values, add Revenue. Leave Summarize by as SUM.
- Under Values, add Revenue again. Set Summarize by to AVERAGE.
- Under Values, add Rep. Set Summarize by to COUNTUNIQUE.
- Under Values, add Revenue a third time. Set Summarize by to COUNTA.
The result is:
| Region | SUM of Revenue | AVERAGE of Revenue | COUNTUNIQUE of Rep | COUNTA of Revenue |
|---|---|---|---|---|
| East | 1900 | 633.33 | 2 | 3 |
| West | 3500 | 1166.67 | 2 | 3 |
| Grand total | 5400 | 900 | 4 | 6 |
Look at the Grand total row for COUNTUNIQUE. It shows 4, not the sum of the column (2 + 2 = 4 here, by coincidence). The grand total is calculated across all rows again, so it is the number of distinct reps in the whole table. Here there are four: Dana, Omar, Priya and Lena. If one rep sold in both regions, the grand total would be lower than the column sum. The same rule applies to AVERAGE: the grand total is the average over all six rows (900), not the average of the two region averages.
You can check the SUM cell for West against the source data with a formula:
=SUMIFS(Sales!E:E, Sales!B:B, "West")This returns 3500, which matches the pivot table.
Renaming and formatting value columns
The default header is the function and field name, such as "SUM of Revenue". Click the header cell in the pivot table and type a new name, or edit the label in the editor. A clear name matters when the same field appears in Values several times.
Number formatting works on the pivot table cells like any other range. Select the value cells and apply a number, currency or percent format. Sheets keeps the format when the pivot refreshes, as long as the same cells are still part of the pivot output.
Custom formulas in Values
Choosing CUSTOM from Summarize by lets you write a formula that combines summarized fields. For example, to calculate revenue per unit for each group, add Revenue and Units to Values, then add a third entry and set Summarize by to CUSTOM. Enter:
=SUM(Revenue)/SUM(Units)The formula works on the group totals, not on each source row. This is why it gives the true ratio per group. Averaging a per-row ratio column would give each row the same weight regardless of size. Chapter 12 returns to this under calculated fields.
Common errors
- Counting instead of summing. Numbers stored as text push the default to COUNTA. Convert the source column.
- Wrong count of people or customers. Use COUNTUNIQUE when you want distinct values, not COUNTA.
- Blank cells missing from counts. COUNTA skips empty cells. Count a field that is always filled in.
- Averaging averages. Do not average the AVERAGE column by hand. The pivot grand total already averages across the underlying rows.
- Stale totals after editing. If you added rows below the source range, the pivot table does not see them. Chapter 11 covers how to extend the range.
How the calculation flows
Filters run first, so a filtered-out row never reaches the function. Each value cell applies the function to one group. The Grand total applies the same function to all remaining rows together.
Exercise
A pivot table has Product in Rows and Rep in Values. Dana sold Widgets four times and Omar sold Widgets twice. What do COUNTA of Rep and COUNTUNIQUE of Rep show for the Widget row, and why might a Revenue field show a count instead of a total?
Show answer
COUNTA of Rep shows 6, because it counts every non-empty Rep cell. COUNTUNIQUE of Rep shows 2, because only Dana and Omar appear. A Revenue field shows a count when its cells are stored as text, because Sheets defaults text fields to COUNTA. Convert the source column to numbers and set Summarize by to SUM.
Exercise
In the worked example, what would the Grand total of AVERAGE of Revenue be if you computed it as the average of the two region averages, and why does the pivot table show 900 instead?
Show answer
The average of 633.33 and 1166.67 is 900, which happens to match here because both regions have three rows. With unequal row counts the two would differ. The pivot table applies AVERAGE to all six underlying rows (5400 / 6 = 900), so it is always weighted by row count.