Calculated Fields in a Pivot Table
By ExcelReady TeamUpdated 5 min read
The short answer
A calculated field is a new value column you create inside a pivot table from a formula, such as =Sales-Cost for profit. Click the pivot, go to PivotTable Analyze > Fields, Items & Sets > Calculated Field, type a name and formula, then click Add. It works on summed fields, so ratios work but row-level maths like Units*Price doesn't.
Key takeaways
- Insert one from PivotTable Analyze > Fields, Items & Sets > Calculated Field.
- The formula uses field names, not cells: =(Sales-Cost)/Sales gives the margin.
- Calculated fields work on the sums of fields, so ratios are right but Units*Price is not.
- For row-level maths, add a helper column to the source data and refresh instead.
- Edit or delete a calculated field from the same dialog by picking its name.
On this page+
A calculated field in a pivot table is a new value you build from a formula, such as profit from Sales minus Cost, without adding a column to your data. You create it once and it fills in for every row, column and total of the pivot. This guide shows the steps, the one rule that makes calculated fields go wrong, and how to edit or remove them.
What is a calculated field?#
A calculated field is a formula that uses other fields in the pivot's source data. It appears in the PivotTable Fields list like a normal field, and you drag it into Values. Common examples:
| Calculated field | Formula |
|---|---|
| Profit | =Sales-Cost |
| Margin | =(Sales-Cost)/Sales |
| Average price | =Sales/Units |
| Growth | =(Sales2024-Sales2023)/Sales2023 |
The examples use this list in A1:E9:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Product | Units | Sales | Cost |
| 2 | East | Laptop | 3 | 3600 | 2700 |
| 3 | West | Phone | 5 | 3000 | 2100 |
| 4 | East | Phone | 4 | 2400 | 1800 |
| 5 | South | Laptop | 2 | 2400 | 1700 |
| 6 | West | Laptop | 1 | 1200 | 900 |
| 7 | East | Tablet | 6 | 1800 | 1100 |
| 8 | North | Phone | 2 | 1200 | 800 |
| 9 | South | Tablet | 3 | 900 | 600 |
How to add a calculated field to a pivot table#
Start with a pivot that has Region in Rows and Sales in Values. Then:
- Click any cell inside the pivot.
- Go to PivotTable Analyze > Fields, Items & Sets > Calculated Field. The menu is the same on Windows and Mac.
- In Name, type
Margin. - In Formula, delete the 0 after the equals sign. Type
=(, double-click Sales in the Fields list, type-, double-click Cost, type)/, and double-click Sales again. The formula reads=(Sales-Cost)/Sales. - Click Add, then OK.
Excel adds Sum of Margin to the Values area. It shows decimals like 0.282, so format it: click the field's drop-down in the Values box, choose Value Field Settings > Number Format and pick Percentage.
| Region | Sum of Sales | Sum of Margin |
|---|---|---|
| East | 7800 | 28.2% |
| North | 1200 | 33.3% |
| South | 3300 | 30.3% |
| West | 4200 | 28.6% |
| Grand Total | 16500 | 29.1% |
To rename "Sum of Margin", click the heading cell and type a new name. It can't be exactly the same as a field name, so type Margin % or add a space at the end.
The rule: calculated fields use totals, not rows#
A calculated field doesn't run on each source row. Excel first sums each field for the group, then applies your formula to those sums. For East, the margin is (7,800 − 5,600) / 7,800 = 28.2%. That is the right answer for a ratio, because a group's margin should come from its total sales and total cost.
The same rule breaks formulas that must work row by row. Imagine the data had Units and Price instead of Sales, with prices of 1,200 for laptops, 600 for phones and 300 for tablets. A calculated field =Units*Price for East would multiply total units (3 + 4 + 6 = 13) by the sum of the prices (1,200 + 600 + 300 = 2,100) and show 27,300. The real East sales are 3×1,200 + 4×600 + 6×300 = 7,800.
The fix is to do row-level maths in the source data: add a Sales column with =C2*D2 filled down, refresh the pivot, and sum that column. Keep calculated fields for ratios and differences of totals.
Calculated fields for percent change#
If your data has one column per year, a calculated field can show growth. With Sales2023 and Sales2024 columns, the formula =(Sales2024-Sales2023)/Sales2023 gives each group's percent change, formatted as a percentage. It follows the usual percent change rule, (new − old) / old.
If the year is a field instead, with one Year column and one Sales column, you don't need a calculated field. Put Year in Columns, then right-click a value and choose Show Values As > % Difference From, with Year as the base field and (previous) as the base item. For a share of the total instead of growth, use percent of total in a pivot table.
How to edit, list or delete a calculated field#
All three happen in the same places:
- Edit. Open Calculated Field again, pick the field in the Name drop-down, change the formula and click Modify.
- Delete. Pick the field in Name and click Delete. Unticking it in the field list only hides it, and it still exists in the pivot cache.
- List all formulas. Go to PivotTable Analyze > Fields, Items & Sets > List Formulas. Excel adds a new sheet listing every calculated field and its formula, which is useful when you take over someone else's file.
Limits and common errors#
Calculated fields are handy, but they have limits worth knowing:
- No cell references. You can't use
B1or a named range in the formula. Put the number in the formula itself. - #DIV/0! in some rows. A group with zero sales divides by zero. Use
=IF(Sales=0,0,(Sales-Cost)/Sales). - Greyed out. The option isn't available in pivots built on the Data Model; those use measures.
- Not the same as a calculated item. A calculated item adds a new item inside a field, such as "East + West" in Region. It's rarely needed and easy to double-count with.
- Errors after renaming source headers. If a field the formula uses disappears from the source, the pivot can't refresh. See the fix for the pivot field name is not valid error.
When a report needs ratios in fixed cells, a formula like =(SUM(D2:D9)-SUM(E2:E9))/SUM(D2:D9) gives the overall 29.1% margin with no pivot at all. The comparison of pivot tables vs SUMIFS helps you choose. Margins by month work too, once you group the dates in the pivot.
Practise it#
Calculated fields and the "totals, not rows" rule are favourite topics in pivot table interview questions. Practise pivot tables in a live spreadsheet, with nested rows, filters and percent of total, checked instantly. Then practise percentages and percent change so the margin and growth formulas come naturally.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
A calculated field =(Sales-Cost)/Sales would show the overall margin in the Grand Total row. Check it with a formula: in G2, subtract the total of E2:E9 from the total of D2:D9, then divide by the total of D2:D9.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Cost | Overall margin | ||||||
| 2 | ||||||||
| 3 | ||||||||
| 4 | ||||||||
| 5 | ||||||||
| 6 | ||||||||
| 7 | ||||||||
| 8 | ||||||||
| 9 | ||||||||
| 10 | ||||||||
| 11 | ||||||||
| 12 |
Tip: Put the subtraction in brackets so it happens first: (SUM of sales minus SUM of cost), then divide by SUM of sales.
Practise this in a lesson
Frequently asked questions
How do I add a calculated field to a pivot table?
Click inside the pivot, go to PivotTable Analyze > Fields, Items & Sets > Calculated Field. Type a name, build the formula with field names such as =Sales-Cost, click Add and then OK.
Why is my pivot table calculated field wrong?
Calculated fields work on the total of each field, not row by row. A formula like =Units*Price multiplies total units by total price. Add a Sales column to the source data instead.
Can a calculated field reference a cell?
No. Calculated field formulas can only use numbers, operators, some worksheet functions and other fields from the pivot's source. Cell references and named ranges aren't allowed.
How do I delete a calculated field in a pivot table?
Open the Calculated Field dialog again, choose the field in the Name drop-down and click Delete. Unticking it in the field list only hides it.
Why is Calculated Field greyed out?
The pivot was built on the Data Model, which uses measures instead of calculated fields. Calculated Field is also unavailable if the active cell isn't inside the pivot.