Adding a formula to a pivot table lets you create calculated fields and calculated items—custom calculations that use the data already in your pivot table, like a profit margin or a sales bonus. This guide covers both methods, step by step, for Microsoft Excel for Microsoft 365 on Windows. You’ll need a pivot table already created from your data, and you’ll work in the PivotTable Analyze tab (called Analyze on Mac).
What You’ll Need
- A pivot table already inserted in your workbook (select any cell inside it).
- The source data should have numeric values for calculations (e.g., Sales, Cost).
- For calculated items: your pivot table must have a field with multiple items (e.g., months, regions).
- Basic understanding of Excel formulas (like
=Sales - Cost).
Step-by-Step
- Select your pivot table. Click anywhere inside the pivot table. This activates the PivotTable Analyze tab (on Mac: Analyze) in the ribbon.
- Open the Fields, Items & Sets menu. Go to PivotTable Analyze > Fields, Items, & Sets (on Mac: Analyze > Fields, Items, & Sets).
- Choose Calculated Field or Calculated Item.
- Choose Calculated Field to add a new field that uses other fields in the pivot table (e.g., Profit = Sales – Cost).
- Choose Calculated Item to add a new item within an existing field, using other items from that same field (e.g., a “Total” that sums two months).
- For a Calculated Field:
- In the dialog box, type a name in the Name box (e.g., “Profit”).
- In the Formula box, type your formula using field names from the list. For example, to subtract Cost from Sales, type
= Sales - Cost. You can double-click field names to insert them, or type them manually. - Click Add, then OK. The new field appears in the PivotTable Field List under “Values” and is added to your pivot table as a new column.
- For a Calculated Item:
- First, select a cell in the pivot table that belongs to the field where you want the item (e.g., select a cell under “Months”).
- Go to PivotTable Analyze > Fields, Items, & Sets > Calculated Item.
- In the dialog, give the item a Name (e.g., “Q1 Total”).
- In the Formula box, type a formula using item names from the field. For example,
= Jan + Feb + Mar(type the item names exactly as they appear, or select them from the “Items” list and click “Insert Item”). - Click Add, then OK. The new item appears in the pivot table as a row or column within that field.
- Edit or delete a formula. To modify, repeat steps 2–3, select the formula from the list, edit it, and click Modify (or Delete to remove).
Common Mistakes
- Using cell references (like
=B2-C2) in a pivot table formula. Pivot table formulas must use field names and item names, not cell addresses. - Typing field names with spaces or special characters without enclosing them in single quotes. For example,
= 'Sales Amount' - 'Cost'is correct if the field name has a space. - Adding a calculated item to the wrong field. Calculated items are tied to a specific field; if you select a cell in the wrong field, the item may appear in an unexpected place.
- Forgetting to refresh after changing source data. The formula recalculates when you refresh, but not automatically if you change the underlying data.
- Using a calculated field when you need a calculated item (or vice versa). A calculated field works across rows/columns; a calculated item works within a single field.
Tips
- Use calculated fields for ratios or totals that involve multiple fields (e.g.,
= Sales / Quantity). Use calculated items for comparisons between items in the same field (e.g.,= 2023 - 2022). - If your formula uses a field name with a space, wrap it in single quotes:
= 'Sales Amount' * 0.1. - Test your formula with simple numbers first. For example, if Sales is 100 and Cost is 60,
= Sales - Costshould return 40. - Calculated fields appear in the PivotTable Field List under “Values”. You can drag them to other areas (e.g., Rows) if needed.
- To see the formula behind a calculated field, go to PivotTable Analyze > Fields, Items, & Sets > List Formulas. This generates a new sheet with all formulas.
- On Mac, the ribbon path is Analyze > Fields, Items, & Sets (same options).
Troubleshooting
- Formula not working / error “#NAME?” – Check that you used field names exactly as they appear in the field list, and that any names with spaces are in single quotes. Also, ensure you didn’t accidentally use cell references.
- Calculated item not showing up – Make sure you selected a cell in the correct field before creating the item. Also, the item may be hidden; check the field’s drop-down list and ensure the item is checked.
- Formula returns wrong results – Verify that your source data is correct and that you refreshed the pivot table (right-click > Refresh). Also check the calculation order: calculated items are evaluated before calculated fields, which can affect results.
- Cannot insert calculated item – Calculated items are not available if the field is grouped (e.g., dates grouped by month) or if the pivot table is in Compact Layout. Try ungrouping or switching to Outline/Tabular layout.
- “Reference is not valid” error – This often happens when you use a field name that doesn’t exist. Double-check the spelling and that the field is in the pivot table.
- Formula disappears after refresh – This is rare, but if it happens, ensure you didn’t accidentally delete it. If the source data range changes, the formula should persist, but if you recreate the pivot table, you’ll need to re-add it.
Frequently Asked Questions
- Can I use Excel functions like SUM or IF in a pivot table formula? Yes, you can use functions in calculated fields and items, but they operate on the aggregate values, not individual rows. For example,
=IF(Sales>100, Sales*0.1, 0)works, but it evaluates per cell in the pivot table. - Why can’t I insert a calculated item? Calculated items are disabled if the pivot table is in Compact Layout, if the field is grouped, or if the field is in the Filters area. Switch to Tabular or Outline layout, ungroup, or move the field to Rows/Columns.
- Do calculated fields work in Google Sheets? No, Google Sheets does not support calculated fields in pivot tables. You would need to add a helper column in your source data or use a separate formula outside the pivot table.
- How do I remove a calculated field? Go to PivotTable Analyze > Fields, Items, & Sets > Calculated Field, select the field from the list, and click Delete. This removes it from the pivot table.
- Can I reference a calculated field in another calculated field? Yes, you can reference a calculated field in another calculated field, but be cautious of circular references. For example, if you create “Profit” as a calculated field, you can create “Profit %” using
=Profit / Sales. - Will my formula update when I add new data? Yes, if you refresh the pivot table after adding data to the source range. The formula recalculates based on the updated data. If you add new rows outside the original source range, you may need to update the pivot table’s source range.
Related
- Solar Installation with Battery Calculator: How to Size
- Traffic Signs Manual Chapter 5: All You Need
- Bosch PS41 Impact Driver: Specs, Power, and Real-World Use
Try it: the Percentage Formula Generator: percent of, percent change, increase and decrease, with the formula.
More in Charts & pivot tables
- Power Pivot in Excel: What It Does and How to Use ItPower Pivot is Excel’s data-modeling feature: it lets you connect and relate multiple tables, create calculations with the…
- Excel Gantt Chart: Exclude Weekends in Your ScheduleYes. To make an Excel Gantt chart exclude weekends, build its timeline from working dates rather than consecutive…
- How to Create a Chart Audit Form in Excel: Step by StepCreate a chart audit form in Excel by listing each audit as one row, adding consistent Yes/No/N/A fields…
- Word Bubble Chart in Excel: Build One Step by StepExcel does not have a built-in word-cloud chart, but you can make a word bubble chart by plotting…
- Add a Goal Line to an Excel Chart: Steps That WorkTo add a goal line to an Excel chart, add a second data series containing the goal value…
- Excel Trendline Definition: Meaning, Types, and UsesAn Excel trendline is a line or curve added to a chart to summarize the general direction or…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.