Sub topic 7
Add a calculated field
A calculated field is a new value in a pivot table, computed from columns in the source data. It lets you measure something that is not stored directly, such as profit, margin, or revenue per unit.
This chapter assumes that you can create a pivot table and add fields to its Rows, Columns, Values, and Filters sections. It also assumes that your source data has one header row and one record per row.
Create a calculated field
Use the sample source table from the earlier chapters:
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 420To add a calculated field:
- Click inside the pivot table.
- In the Pivot table editor, find the Values section.
- Click Add.
- Choose Calculated field.
- Enter a name, such as
Profit. - Enter this formula:
=Revenue - Cost- Press Enter or click away from the editor.
Google Sheets adds Profit as another value in the pivot table. If Region is in Rows, each region displays its calculated profit.
For example, the West rows contain revenue of 670 and cost of 395. Their profit is therefore 275. The calculated field applies the formula to the source records represented by each pivot group.
Write formulas with source column names
A calculated-field formula uses arithmetic and source column names. Common operators include:
+for addition-for subtraction*for multiplication/for division
If a header contains spaces, place the header name in single quotation marks:
='Unit Price' * QuantityThis formula creates a value for each source record by multiplying Unit Price by Quantity.
Keep headers simple when you can. Headers such as Revenue, Cost, and Units are easier to use than headers with punctuation or inconsistent spelling. If you rename a source header later, check the calculated field. The old formula may no longer match the source column.
Calculated fields can refer to numeric source columns. They should not be used as a general-purpose formula area for worksheet functions that depend on individual cell locations. The formula is evaluated within the pivot table's aggregation model.
Check the result against the source data
A calculated field can look plausible while still using the wrong columns. Verify it with an independent calculation:
- Filter or group the pivot table so that you can identify one small group.
- Add the group's Revenue and Cost values.
- Calculate Revenue minus Cost separately.
- Compare that result with the Profit value.
For the complete sample, Revenue is 1,550 and Cost is 980. Profit should be 570.
The check is especially important when the source contains blanks, text that looks numeric, duplicate records, or rows outside the pivot source range.
Choose the correct aggregation model
A calculated field can represent different kinds of measures. Profit is usually additive because the total profit equals the sum of the row profits:
(Revenue - Cost) for row 1
+ (Revenue - Cost) for row 2
+ ...Ratios need more care. Suppose you want revenue per unit. This formula gives the correct group-level ratio when the fields are aggregated first:
=SUM(Revenue) / SUM(Units)Do not assume that a pivot table's sum of row-level ratios equals the ratio for the whole group. For example, the revenue-per-unit value for one record may be very different from the combined revenue divided by combined units. The order of aggregation changes the result.
Use the calculated field's Summarize by setting and inspect the available options. If you need a custom aggregate formula, choose Custom when it is available and test the result against a manual calculation.
Use a calculated field with grouped rows
Calculated fields and grouping solve different problems:
- A group changes how source items are labeled and combined.
- A calculated field creates a new measure from source columns.
For example, group Date by month, place Region in Rows, and add Profit as a calculated field. The pivot table can then show monthly profit by region. The date group controls the rows or columns, while Profit controls the value being measured.
If a calculated field is missing, check that the pivot source includes the columns used by the formula, the headers are unique, and the source values are numeric.
Exercise
A pivot table shows Revenue and Cost by Region. Which calculated-field formula creates profit, and what total profit should the sample data produce?
Show answer
Use =Revenue - Cost. The sample total is 1,550 minus 980, which equals 570.