Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel PivotTable Calculated Field


Share

Calculated Field

A calculated field is a new field that you make with a formula. The formula uses the other fields, like Sales and Cost.

The new field lives in the PivotTable. The source data does not change.

This chapter uses Poke Mart sales data. Download it to follow along: poke_mart_sales.xlsx

Start with a PivotTable that has Category in Rows and Sum of Sales in Values, formatted with a thousands separator. See Create a PivotTable and PivotTable Values.

Add a Calculated Field

The data has Sales and Cost, but no Profit. Let's add it: Profit = Sales - Cost.

  1. Click any cell in the PivotTable
  2. Click PivotTable Analyze > Fields, Items, & Sets > Calculated Field

The PivotTable Analyze tab with the Fields, Items, and Sets menu open and Calculated Field highlighted

The Insert Calculated Field dialog opens.

  1. Type Profit in the Name box
  2. Delete the 0 in the Formula box
  3. Double-click Sales in the Fields list, type a minus sign, and double-click Cost
  4. Click Add, then OK

The formula is now:

= Sales - Cost

The Insert Calculated Field dialog with the name Profit and the formula = Sales - Cost

Excel adds Profit to the field list, and puts Sum of Profit in the Values area.

Format it with a thousands separator, the same way as Sum of Sales:

ABC
3Row LabelsSum of SalesSum of Profit
4Balls4,447,2001,969,640
5Medicine4,413,6002,027,060
6Status Healers556,000295,495
7Grand Total9,416,8004,292,195

The Poke Mart made 4,292,195 in profit.

Excel puts "Sum of" in front of every calculated field. You can rename it in Value Field Settings, as in PivotTable Values.



Margin as a Percentage

A calculated field can use another calculated field. Let's add the margin: the share of each sale that is profit.

  1. Open Fields, Items, & Sets > Calculated Field again
  2. Name: Margin
  3. Formula: = Profit / Sales
  4. Click Add, then OK

Excel shows the margin as a decimal, like 0.442894405. To show it as a percentage:

  1. Open Value Field Settings for Sum of Margin
  2. Click Number Format and choose Percentage with 2 decimal places
  3. Click OK twice
ABCD
3Row LabelsSum of SalesSum of ProfitSum of Margin
4Balls4,447,2001,969,64044.29%
5Medicine4,413,6002,027,06045.93%
6Status Healers556,000295,49553.15%
7Grand Total9,416,8004,292,19545.58%

Status Healers have the smallest sales, but the best margin.

Look at the Grand Total: 45.58%. That is the total profit divided by the total sales: 4,292,195 / 9,416,800.

It is not the average of the three margins above it. That is the right answer, and the next section explains why.


Calculated Fields Work on Sums

This is the most important thing to know about calculated fields.

Excel does not run the formula on each row of the data. It first sums each field for the PivotTable row, and then runs the formula on the sums.

For Balls, Margin is calculated like this: (sum of Sales - sum of Cost) / sum of Sales. That is exactly how a margin should work.

But it goes wrong for formulas that are meant to run on each row, especially with a price like UnitPrice. A sum of prices means nothing.

Correct and Incorrect

Uncheck Profit and Margin. Then add two more calculated fields:

  • Revenue with the formula = Quantity * UnitPrice (incorrect)
  • Avg Price with the formula = Sales / Quantity (correct)

Format Revenue with a thousands separator, and Avg Price with 2 decimal places:

ABCD
3Row LabelsSum of SalesSum of RevenueSum of Avg Price
4Balls4,447,2006,646,578,400350.34
5Medicine4,413,6006,660,055,500532.08
6Status Healers556,000356,373,150158.90
7Grand Total9,416,80034,977,434,800384.55

Revenue is wrong. In the data, Sales is Quantity * UnitPrice on each row, so Revenue should match Sales.

Instead, Excel multiplied the total quantity for Balls (12,694) by the sum of the unit prices of all 1,035 ball orders (523,600).

The Grand Total is not even the sum of the rows above it.

Avg Price is right. Total sales divided by total items sold is the average price of one item: 4,447,200 / 12,694 = 350.34 for Balls.

Note: Do math that belongs to each row, like Quantity * UnitPrice, in a new column in the source data. Use calculated fields for math on totals, like profit, margin or average price.


Change or Delete a Calculated Field

To change a calculated field:

  1. Open Fields, Items, & Sets > Calculated Field
  2. Pick the field in the Name list, for example Margin
  3. Change the formula
  4. Click Modify, then OK

To delete it, pick it in the Name list and click Delete.

Unchecking a calculated field in the PivotTable Fields pane only takes it out of the PivotTable. It stays in the field list until you delete it.

Note: If Calculated Field is grayed out, the PivotTable probably uses the Data Model. Those PivotTables use measures instead of calculated fields.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.