Sub topic 7
Add a calculated field
A calculated field is a new measure that a pivot table builds from your source columns. You write the formula once, and the pivot applies it to every row of the source data. This chapter covers where to create one, how Sheets evaluates it, how to check the result, and what usually goes wrong.
Prerequisites
This chapter assumes you can already do the following:
- Build a pivot table with rows, columns, values, and filters.
- Read a pivot's summarize-by setting (SUM, COUNT, AVERAGE).
- Keep source data in a table with one header row and one record per row, with numbers stored as numbers and dates stored as real dates.
The next chapter covers formula syntax in detail. The chapter after that explains why ratios behave differently from sums.
What a calculated field is
A normal pivot value summarizes one source column, for example the sum of Revenue. A calculated field summarizes an expression that combines several columns, for example Revenue minus Cost. The source table has no Profit column, and you don't add one. The pivot computes Profit itself.
This has three practical consequences:
- The source sheet stays unchanged. Nothing is written back to it.
- The formula refers to columns by their header names, not by cell addresses such as
D2. - A calculated field exists only in the Values section of a pivot. You can't drag it into Rows, Columns, or Filters.
The running example
The examples use this small table. Paste it into a sheet with the header in row 1.
Date Region Product Units Revenue Cost
2026-01-05 West Widget 10 250 150
2026-01-19 East Widget 4 100 60
2026-02-02 West Gadget 7 420 245
2026-02-23 South Gadget 3 180 105
2026-03-09 East Gizmo 12 600 420The goal is profit by region, where profit is revenue minus cost.
Worked example: Profit by region
Create the pivot
- Select the whole table, including the header row.
- Choose Insert, then Pivot table. Place it in a new sheet.
- In the editor, next to Rows, choose Add and pick Region.
At this point the pivot lists West, East, and South with nothing beside them.
Add the calculated field
- Next to Values, choose Add.
- Choose Calculated field at the bottom of the list.
- In the formula box, enter the formula below.
=Revenue - CostSheets names the new value "Calculated Field 1" and summarizes it with SUM. Click the name in the Values card and type Profit to rename it. This changes only the column label in the pivot.
Check the result
Compute each source row's profit by hand and add up the rows by region.
| Region | Rows used (Revenue − Cost) | Expected Profit |
|---|---|---|
| West | 250 − 150 = 100; 420 − 245 = 175 | 275 |
| East | 100 − 60 = 40; 600 − 420 = 180 | 220 |
| South | 180 − 105 = 75 | 75 |
| Grand total | 570 |
The pivot should show 275, 220, 75, and a grand total of 570. As a cross-check, total revenue is 1550 and total cost is 980, and 1550 − 980 = 570. If your pivot disagrees, see the troubleshooting section below.
How Sheets evaluates a calculated field
With the default setting (Summarize by SUM), Sheets works in two steps. First it evaluates your formula for each source row. Then it sums those per-row results within each pivot group.
For =Revenue - Cost the order does not matter. Subtraction distributes over addition, so the sum of per-row differences equals the difference of sums. This is why profit is the safest first calculated field.
The order does matter for ratios. Consider revenue per unit as =Revenue / Units with SUM summarization. The West region's two rows give 250 / 10 = 25 and 420 / 7 = 60. Summed, that is 85, which is not a price. The correct West figure is (250 + 420) / (10 + 7), about 39.41. The custom aggregation chapter covers the fix, which is to summarize by Custom and aggregate each column first. For now, remember that a SUM-summarized calculated field sums per-row results.
Calculated field or helper column?
You can get the same Profit result by adding a column to the source and pivoting on it. Both approaches are valid. The table compares them.
| Question | Calculated field | Helper column in source |
|---|---|---|
| Does it change the source sheet? | No | Yes |
| Where is the formula written? | In the pivot editor | In cells, one per row |
| Can it use any cell reference or function? | No, only source column names and supported functions | Yes |
| Can you use it in Rows, Columns, or Filters? | No, Values only | Yes |
| Does it extend to new rows automatically? | Yes, if the pivot range covers them | Only if you fill the formula down |
| Can you control aggregation order? | Yes, with Summarize by Custom | The per-row result is always summed or counted |
Choose a calculated field when you want a measure that lives with the pivot. Choose a helper column when you need to group or filter by the result. For example, "profitable or not" needs to be a row field, so it must exist in the source.
Editing and removing a calculated field
- To change the formula, open the pivot editor and click the calculated field's card in Values. The formula box is editable. The pivot updates when you finish.
- To change how it is summarized, use the Summarize by dropdown on the same card.
- To remove it, click the X on the card. The source data is not affected.
- You can add several calculated fields to one pivot, and you can mix them with ordinary value fields. For example, show Revenue, Cost, and Profit side by side.
Names with spaces
If a header contains a space, wrap the name in single quotes inside the formula.
='Unit Price' * QuantityHeader names are matched exactly, so Revenue and revenue are best treated as different strings until you have tested them. If you rename a source header later, update the formula to match.
Common errors and how to diagnose them
The pivot shows an error instead of numbers
The usual cause is a column name that does not match any header. Check for typos, extra spaces, or a header that you renamed after writing the formula. Names with spaces need single quotes. Confirm that the pivot's source range includes the header row.
The result is all zeros or too low
A numeric column may contain text values, such as "250" stored as text or $250 typed with a symbol that Sheets did not convert. Text in a numeric column does not take part in arithmetic the way a number does. Select the column and check that values are right-aligned, or use =ISNUMBER(E2) in a spare cell. Convert the text to numbers and refresh the pivot.
Blank cells give strange results
A blank Cost in one row makes that row's profit equal to its full revenue, because the blank behaves like zero in arithmetic. Fill blanks with real values, or remove those rows from the source range, before you trust the totals.
New rows do not appear
If the pivot's source range was fixed as A1:F6, a new row 7 is not included. Edit the data range in the pivot editor, or define the source as whole columns such as A:F so that new rows are picked up. Whole-column ranges can include notes below the table, so keep that area empty.
The grand total looks wrong for a ratio
This is the per-row sum problem described above. Rebuild the field with Summarize by Custom and aggregate each column inside the formula.
Totals differ from a manual check
Look for filters on the pivot, such as a filter on Region, that exclude rows. Also look for hidden rows in the source. Compare your hand totals to the pivot with filters cleared.
Limits worth remembering
- A calculated field can't be placed in Rows, Columns, or Filters.
- It can't reference cells or ranges outside the pivot's source columns.
- The formula runs against the source table. It does not see the pivot's own grouped or displayed totals.
- Each calculated field is evaluated across the entire source range. Very large tables with several complex fields may recalculate slowly.
Putting it together
- Confirm that the source columns are numeric and the header names are exact.
- Create the pivot with a row field such as Region.
- Choose Values, Add, Calculated field, and enter a formula that uses header names.
- Rename the field to something readable.
- Verify the result against a hand calculation and against the totals of the source columns.
- If the formula involves a division, switch the summarize setting to Custom and aggregate first, as covered in the later chapter on custom aggregation.
Exercise
Using the running example, you add a calculated field with the formula =Revenue - Cost, summarized by SUM, and put Product in Rows. What Profit values should the pivot show for Widget, Gadget, and Gizmo, and what is the grand total?
Show answer
Widget has two rows, (250 − 150) + (100 − 60) = 100 + 40 = 140. Gadget has two rows, (420 − 245) + (180 − 105) = 175 + 75 = 250. Gizmo has one row, 600 − 420 = 180. The grand total is 140 + 250 + 180 = 570, which matches total revenue 1550 minus total cost 980.
Exercise
A colleague adds a calculated field =Revenue / Units, leaves it on SUM, and puts Region in Rows. Without computing the sheet, explain why the West row will not show the revenue per unit for West, and give the number it shows versus the correct number.
Show answer
With SUM, Sheets divides on each source row first and then adds the results. West has rows with 250/10 = 25 and 420/7 = 60, so the pivot shows 85. The correct revenue per unit for West is the total revenue divided by the total units, (250 + 420) / (10 + 7) = 670 / 17, about 39.41. The fix is to summarize by Custom with =SUM(Revenue) / SUM(Units).
Exercise
Your source header is "Unit Price" and another is "Quantity". Write the calculated field formula for line total, and say what happens if you leave out the single quotes.
Show answer
Use ='Unit Price' * Quantity. Without the single quotes, Sheets cannot read "Unit Price" as one column name because of the space, so the formula is not recognized and the pivot shows an error instead of values.