All-Access, every lesson, no ads. $8.25 a month.See the plans →

Calculated Field in a Pivot Table: Create, Edit, Fix

By the LogicExcel Editorial Team••14 min read•2,746 words

Calculated Field in a Pivot Table: Create, Edit, Fix

Analyst creating a PivotTable calculated field

A calculated field is a custom formula that lives inside your PivotTable and works on the other fields in it. To add one, select the PivotTable, go to PivotTable Analyze > Fields, Items, & Sets > Calculated Field, type a name and a formula such as =Sales*15%, and select Add. This guide covers that process, then the limits that trip people up, the calculated item, and grouping dates by week, month or year.

TL;DR

  • Create a calculated field from the PivotTable Analyze tab: Fields, Items, & Sets > Calculated Field. Name it, write the formula with field names, select Add.
  • Calculated fields work on the summed data, not on individual rows. That is why ratios and averages sometimes look "wrong" until you understand it.
  • Use Show Values As for percent of total, running total, rank and difference. Use a calculated field when you need your own formula.
  • A calculated item combines items inside one field. A calculated field combines different fields.
  • Date grouping fails when the "dates" are really text or the source range has blanks. Fix the data first.

Table of Contents

What a calculated field does

A PivotTable summarizes your data by adding it up, counting it or averaging it. Sometimes the number you need is not in the source data. You have Revenue and Units, but you want revenue per unit. You have Sales, but you want a 15% commission. You have Sales and Cost, but you want Profit.

You could add a helper column to the source table. A calculated field is the alternative: the formula lives in the PivotTable, appears in the Field List like any other field, and can be dragged into the Values area. Microsoft describes the difference this way: a calculated field uses data from other PivotTable fields, while a calculated item works with items inside a single field.

The formula can use the names of fields, much like a worksheet formula uses cell references. A simple example from Microsoft's documentation is =Sales*15%.

How to add a calculated field, step by step

The path is the same in recent Windows versions of Excel (Microsoft's documentation covers Microsoft 365 and Excel 2024, 2021, 2019 and 2016).

  1. Click any cell inside the PivotTable.
  2. On the ribbon, open PivotTable Analyze, then Fields, Items, & Sets, then Calculated Field.
  3. In Name, type a label, for example Profit.
  4. In Formula, build the expression. Delete the default 0, then either type field names or select a field in the Fields list and choose Insert Field. For example: =Sales - Cost.
  5. Select Add, then OK.
The new field now appears in the PivotTable Field List. Tick it, or drag it into Values, and it shows up as a new column.

If you have never built a PivotTable, start with the basics first. Our lesson on PivotTable fundamentals walks through the layout, and a thirty-second PivotTable summary shows how quickly one can be built.

Calculated field formula examples

Here are formulas people use most. Field names are examples, so swap in the ones from your own data.

GoalNameFormula
ProfitProfit=Sales - Cost
Commission at 15%Commission=Sales*15%
Revenue per unitAvgPrice=Revenue/Units
Margin percentageMargin=(Sales - Cost)/Sales
Response rateResponseRate=Responded/Tickets
Bonus on a totalRepBonus=Total*3%
If you build financial summaries from calculations like these, a ready-made business finance dashboard template can give you a layout to drop your PivotTable results into.

For the margin and response-rate formulas, format the result as a percentage. Our guide to Excel percentage formulas covers the number formats and the common mistakes.

Can I use IF in a calculated field?

Yes, many people do. A typical case is paying a commission only when a status says so. You can write something like =IF(Status="Commission", Sales*15%, 0). There is a catch: the calculation runs on the summed data for each cell of the PivotTable, so a text field like Status is evaluated at the level of the whole group, not row by row. If the logic has to run on every record, add a helper column to the source data and summarize that instead. To practice the IF logic itself, try our IF function examples and exercises.

How to view, edit or delete a calculated field

Open PivotTable Analyze > Fields, Items, & Sets > Calculated Field again. In the Name box, pick the field from the dropdown. Change the formula and select Modify. To remove it, choose Delete in the same dialog. This is the documented way to edit one.

Two habits save headaches. First, give each field a name that says what it measures, because it sits next to your source fields in the list. Second, check the formula after any change to the source column names, since the formula refers to fields by name.

Why a calculated field gives unexpected results

Why a calculated field gives unexpected results

Most frustration with calculated fields comes from one fact: the formula works on summed values, not on each row. Microsoft's documentation states the main restrictions: calculated fields cannot use cell references or defined names, cannot refer to totals, and cannot be created in OLAP-based reports.

See the effect with an example. Say you have three orders:

OrderRevenueUnits
A10010
B30020
C505
A field defined as =Revenue/Units returns 450 / 35, about 12.86, for the grand total. It does not average 10, 15 and 10. That is a weighted average, which is usually what you want for price per unit. But if you wanted the plain average of the three order-level prices, a calculated field will not do that. A helper column in the source data would.

Some practical consequences:

  • Totals and subtotals are recalculated, not added up. The grand total of a ratio field is the ratio of the totals. It is not the sum of the visible ratios.
  • You cannot point at a cell. A tax rate stored in a worksheet cell cannot be referenced. Type the rate into the formula, or put it in the source data as a column.
  • Text conditions are blunt. As shown in the IF example, comparisons happen after summing.
Microsoft also gives guidance on when calculated fields or measures are the better tool: measures when the result depends on other fields selected in the PivotTable, and calculated fields for complex calculations such as filtered counts, year-over-year analysis or variance. Measures belong to Power Pivot and the Data Model, which is a step up from the everyday PivotTable.

Show Values As: calculations without a formula

Before you write a formula, check whether the calculation is already built in. Right-click a value in the PivotTable, choose Show Values As, and pick from options such as percent of grand total, difference from, running total and rank. Microsoft notes that you can use Show Values As instead of writing your own calculated fields, and lists Difference From, Running Total and Rank among the custom calculations.

A quick rule for choosing:

You wantUse
Share of the total, running total, rank, change from last periodShow Values As
A new number built from two or more fields (profit, price per unit, bonus)Calculated field
A new row or column that combines items within one fieldCalculated item
A result that depends on filters and contextA measure in the Data Model
You can also combine them. Build a Profit calculated field, then use Show Values As to display each region's profit as a percentage of the grand total.

Calculated item: the other half of the feature

People searching for the calculated field often land on the calculated item, because both sit under the same menu. The difference matters. A calculated field creates a value from other fields. A calculated item creates a new item from items in the same field. If your Region field has East, West and Central, a calculated item could be Coastal = East + West.

To create one, per Microsoft's steps:

  1. Select the field that holds the items, for example a Region heading in the PivotTable. If the field is grouped, ungroup it first.
  2. Choose PivotTable Analyze > Fields, Items, & Sets > Calculated Item.
  3. Enter a name, then build the formula by inserting items from the same field.
  4. Select Add.
A word of caution from experience: calculated items add the new row alongside the originals, so a grand total can double count items that you included in the calculated item. Check the totals after you add one, and hide the originals if they are not needed.

Grouping dates in a PivotTable

Date grouping is the other half of what readers ask about, and it is often what makes a PivotTable useful. A column of daily dates becomes months, quarters or years in a few clicks.

Group by month, quarter or year

Microsoft's procedure for Windows is: right-click a value in the PivotTable, select Group, set Starting at and Ending at if needed, choose a period under By, and select OK. The guide applies to Microsoft 365, Mac, and Excel 2024, 2021, 2019 and 2016. Excel's date grouping supports seconds, minutes, hours, days, months, quarters and years.

To group by month, select Months. If your data spans more than one year, also select Years. Otherwise January 2025 and January 2026 are combined into one "Jan" row, which is rarely what you want.

Group by week

Week is not on the list of periods. The workaround is to group by Days and set Number of days to 7. According to Microsoft Learn, when day grouping is selected, the By value specifies the number of days. Choose your Starting at date carefully, because the first week begins on that date. If you want weeks to start on Monday, enter a Monday. Deselect any other period in the dialog, or the 7-day grouping will not be available.

Four steps for grouping PivotTable dates by week

When the Group option is greyed out or fails

Two causes cover most cases. A Microsoft Q&A answer points out that grouping is unavailable when the source values are text that only look like dates, and that an oversized source range with empty cells can also break it. The fixes:

  • Convert text dates to real dates. Dates align right by default in a cell; text aligns left. Use Data > Text to Columns or a formula such as =DATEVALUE(A2) in a helper column.
  • Remove blanks. Make sure every row in the date column has a date, and limit the source range to your data, or turn the data into an Excel Table so the range adjusts itself.
  • Refresh. After correcting the data, refresh the PivotTable and try again.
If you do monthly reporting, this data hygiene pays off in every report. Our month-end reporting course for accounting and the lesson on summarizing with SUMIFS show how clean source data makes summaries quick.

A worked example from start to finish

Imagine a sales sheet with columns Date, Region, Rep, Revenue and Cost. You want monthly profit and margin by region.

  1. Convert the range to a Table with Ctrl+T, so the PivotTable range grows with new rows.
  2. Insert a PivotTable. Put Region in Rows, Date in Columns, Revenue and Cost in Values.
  3. Right-click a date, choose Group, select Months and Years.
  4. Add a calculated field named Profit with =Revenue - Cost.
  5. Add another named Margin with =(Revenue - Cost)/Revenue, and format it as a percentage.
  6. Right-click the Profit values, choose Show Values As, and then % of Row Total to see which months carry each region.
Ten minutes of work, and nothing in the source data had to change. When the table grows, refresh and every number updates. For a broader look at letting Excel do the repetitive work, see our piece on automating data analysis tasks in Excel, and for the next step in the PivotTable skill, the lesson on working with PivotTables.

Perspective

> The calculated field is a good example of why we built LogicExcel around practice instead of watching. Reading the steps takes a minute. Understanding why a ratio in the grand total is not the average of the rows only sinks in when you type the formula, see the number, and get it wrong once.
>
> That is the moment our exercises are designed for. You enter the formula in an Excel-like environment, get instant feedback, and see an explanation of the mistake. No account, no installation, so nothing sits between you and the repetition that builds muscle memory.
>
> Our advice to analysts, managers and career changers: learn the three tools together. Show Values As for quick comparisons, calculated fields for your own formulas, and clean date columns for grouping. Together they cover most of the reports people are asked to produce.
>
> Thomas Houza

Practice it on real data

Reading about a calculated field is the easy part. Building one, breaking it and fixing it is what makes it stick. LogicExcel offers 95 free Excel exercises with instant feedback, no sign-up and nothing to install. If you want a structured path from the basics to PivotTables and beyond, look at our Excel I to IV courses.

LogicExcel

Preparing for a job test where PivotTables may come up? Try the free Excel test for interviews and assessments.

FAQ

How do I create a calculated field in a PivotTable?

Click inside the PivotTable and open PivotTable Analyze > Fields, Items, & Sets > Calculated Field. Type a name, enter a formula using field names, such as =Sales - Cost, then select Add and OK. The new field appears in the Field List, ready to drag into Values.

How do I see or edit calculated fields in a PivotTable?

Open the same Calculated Field dialog and choose the field name from the Name dropdown. The formula appears in the Formula box. Edit it and select Modify, or select Delete to remove it. Per Microsoft's documentation, this is the way to view and change a calculated field.

What is the difference between a calculated field and a calculated item?

A calculated field builds a new value from other fields, for example Profit from Sales and Cost. A calculated item builds a new item from existing items in one field, for example a Coastal region from East and West. Ungroup the field before adding a calculated item.

Why can't I group dates in my PivotTable?

Usually the dates are stored as text, or the source range includes empty cells. Convert the text to real dates, make sure the date column has no blanks, or turn the data into an Excel Table, then refresh. Weekly grouping needs the Days option with 7 days.

Can a calculated field refer to a worksheet cell?

No. Calculated fields cannot use cell references or defined names. Type the value into the formula, or add it as a column in the source data so the PivotTable can use it as a field.

Sources

Recommended

Keep going

Guides people read next.