A calculated field is a new value field in a pivot table, built from a formula that uses the other fields. It helps when a report needs a figure that isn’t in the source data, such as profit, which is sales minus cost. Because the field lives inside the pivot table, it recalculates when you refresh.
Add one
- Click any cell in the pivot table.
- Go to the PivotTable Analyze tab. In the Calculations group, choose Fields, Items & Sets, then Calculated Field.
- Type a name for the new field, such as Profit.
- In the Formula box, type the formula, starting with an equals sign, such as =Sales-Cost.
- Click Add, then OK.
The new field appears in the Values area. Drag it to a different position if you need to.
Write the formula
A calculated field uses the names of your fields and the basic arithmetic operators: + to add, - to subtract, * to multiply and / to divide. The names must match the column headings in your source data. Single-word headings are the easiest to work with. If a heading has spaces, check the result carefully, because a mistyped name can give a wrong answer.
A calculated field can’t refer to cell addresses such as B2. Every term in the formula is a field, not a cell.
How the result is calculated
This is the part most people miss. A calculated field works on the totals of each field, not on each row. For a region, Excel adds up all the sales for that region, adds up all the cost, and then applies the formula to those two totals.
For a simple difference, this gives the same answer as working out profit row by row and adding it up, because a sum of differences equals the difference of the sums. For a ratio, it does not give the average of the row ratios. It gives the ratio of the totals, which is usually what a report needs, but check what the number means before you share it.
A margin example
Suppose the report has Sales and Cost fields. To work out margin as a share of sales, name the field Margin and use this formula:
=(Sales-Cost)/Sales
Then open Value Field Settings and choose Number Format to show the result as a percentage. If you’re pricing products, the difference between margin and markup matters, and markup vs margin formula in excel explains it.
Common mistakes
- Dividing by zero. If a group’s total in the denominator is zero, the result shows #DIV/0!. The fixes are in how to get rid of #div/0 error in excel.
- Averaging ratios. As explained above, a calculated ratio is the ratio of the totals, not an average of row ratios. Don’t expect the two to match.
- Forgetting the source changed. A calculated field follows the source fields. If you rename a heading in the source, update the formula to match.
For what the other error codes mean, see excel formula error messages explained.
Edit or remove it
To change an existing calculated field, open Fields, Items & Sets, then Calculated Field again. Pick the field from the Name list, then change its formula or delete it. Removing a field takes it out of the Values area, so check the layout afterward.