Calculated field in a Google Sheets pivot table: add one for margin %
Add a calculated field to a Google Sheets pivot table: Values, Add, Calculated Field, =(Revenue-Cost)/Revenue, keep SUM. Why summed Margin % hits 405%
On this page
=(Revenue-Cost)/RevenueBefore SUM of Margin %
| G | H | I | J | |
|---|---|---|---|---|
| 1 | Region | SUM of Revenue | SUM of Cost | SUM of Margin % |
| 2 | East | 10000 | 7900 | 95.00% |
| 3 | North | 9300 | 7000 | 115.00% |
| 4 | South | 8700 | 6300 | 100.00% |
| 5 | West | 9900 | 7800 | 95.00% |
| 6 | Grand Total | 37900 | 29000 | 405.00% |
What changed
- SUM of Margin % removed from Values
- Calculated field
Profit marginadded
After calculated field
| G | H | I | J | |
|---|---|---|---|---|
| 1 | Region | SUM of Revenue | SUM of Cost | Profit margin |
| 2 | East | 10000 | 7900 | 21.00% |
| 3 | North | 9300 | 7000 | 24.73% |
| 4 | South | 8700 | 6300 | 27.59% |
| 5 | West | 9900 | 7800 | 21.21% |
| 6 | Grand Total | 37900 | 29000 | 23.48% |
To add a calculated field to a pivot table in Google Sheets, open the Pivot table editor, click Add next to Values and pick Calculated Field. Type a formula that uses your column headers, such as =(Revenue-Cost)/Revenue, and leave Summarize by on SUM.
North shows a margin of 115.00% in the pivot table on the Broken tab. South is at 100.00%, and the Grand Total row says 405.00%. North brought in 9300 and spent 7000, so a margin above 100% would mean the costs were negative. A pivot table prints numbers like these when a percent column from the source data sits under Values, because it adds the row percentages together. Margin needs a calculated field instead, a value column the pivot table works out from the Revenue and Cost columns. It is added in the Pivot table editor: next to Values, click Add, then Calculated Field.
On the Fixed tab that field is named Profit margin and holds =(Revenue-Cost)/Revenue, with Summarize by left on SUM. It took the place of SUM of Margin % in column J, and North now reads 24.73%.
The source is a small sales list in A1:E13. Each of the twelve rows has a rep, a region, Revenue in column C and Cost in column D. Column E, Margin %, works out each sale on its own with =(C2-D2)/C2, and those row margins are correct.
The numbers go wrong once column E is dragged into the Values section of the pivot table. Sheets put it in as SUM of Margin %, so for North it added Aisha's 20.00%, Priya's 75.00% and Tom's 20.00% and showed 115.00%. The Grand Total cell adds all twelve row margins. Priya's 75.00% came from an 800 sale and Tom's 20.00% from a 6000 sale, and the sum treats them as if they were the same size.

Adding a calculated field for margin % in the Pivot table editor
Google's help page on pivot tables covers this under adding calculated fields with SUM or a custom formula. These are the steps as they went on the Fixed tab.
- Click any cell in the pivot table. If the Pivot table editor panel does not open on the right, click the Edit button that appears under the table.
- Next to Values, click Add. The list opens with Calculated Field at the top, above the source columns Rep, Region, Revenue, Cost and Margin %.
- A dialog titled Add calculated field opens. Its name box is prefilled with Calculated Field 1. Replace that with Profit margin, which becomes the column header in J1.
- In the Formula box, type
=(Revenue-Cost)/Revenue. The Columns tab on the right lists the source headers by name, which is how the formula refers to them, so with other data the two names are whichever revenue and cost headers that tab shows. - Wait for the green check in the lower right corner of the formula box. Google's page says a red exclamation mark in its place means the syntax is not valid. Leave Summarize by on SUM and click Add.
- Back in the editor, find the SUM of Margin % card under Values and click the X on it to take the old column out.
The new column filled J2:J6 straight away, but as long decimals. Selecting J2:J6 and clicking Format as percent on the toolbar turned them into the two-decimal percentages in the figures here.

Why a calculated field on Summarize by SUM divides the totals instead of adding percentages
Column E and the calculated field use the same arithmetic, revenue minus cost, divided by revenue. Column E applies it to each sale, and the pivot then adds the answers. With Summarize by left on SUM, the calculated field gave a different result: in this copy, each region's cell came out as that region's summed Revenue minus summed Cost, divided by summed Revenue.
The check column on the Fixed tab confirms it row by row. L2 holds =ARRAYFORMULA((H2:H6-I2:I6)/H2:H6), which reads the totals already in H and I, and L2:L6 matches J2:J6 exactly: 21.00%, 24.73%, 27.59%, 21.21%, 23.48%. The Grand Total row follows the same rule, (37900 - 29000) / 37900.
Both columns divide and add, in opposite order. Adding first and dividing second gives margin on the money. Dividing first and adding second gives a sum of ratios, which is what the SUM of Margin % column on the Broken tab shows.
SUM or AVERAGE of a percent column against a calculated field, on the same rows
The take-home copy runs the same twelve rows through six setups. North and the Grand Total are enough to see where they split:
| How the margin was added | Column | North | Grand Total |
|---|---|---|---|
| SUM of Margin % (column E in Values) | J of Broken | 115.00% | 405.00% |
| AVERAGE of Margin % (column E in Values) | K of Other results | 38.33% | 33.75% |
Calculated field =(Revenue-Cost)/Revenue, Summarize by SUM | J of Fixed | 24.73% | 23.48% |
Calculated field =(SUM(Revenue)-SUM(Cost))/SUM(Revenue), Summarize by Custom | L of Other results | 24.73% | 23.48% |
Calculated field =(Revenue-Cost)/Revenue, Summarize by Custom | M of Other results | 20.00% | 25.00% |
Formula next to the pivot, =ARRAYFORMULA((H2:H6-I2:I6)/H2:H6) | L of Fixed | 24.73% | 23.48% |
Three setups land on 24.73% for North, the figure from the Fixed tab, and three don't.
AVERAGE looks closer, which makes it harder to catch. It gives each sale an equal vote, so Priya's small sale counts as much as Tom's large one, and North averages 38.33% even though most of its money came from Tom's low-margin sale. The Grand Total under AVERAGE is 33.75%, the plain average of the twelve values in column E, against a real 23.48%.
Column E is still useful for reading one sale at a time. It is only inside the pivot table, under SUM or AVERAGE, that it gives North 115.00% or 38.33% instead of 24.73%.
The Custom result without SUM is the strangest. Column M of Other results shows 25.00% for East, 20.00% for North, 30.00% for South and 15.00% for West. Those are the row margins of Dana, Aisha, Ken and Emily, the first source row of each region, and Grand Total shows Dana's 25.00% again. The formula box still said the formula was valid, and no error appeared anywhere.

Summarize by Custom needs SUM() around every column name
Google's example of a custom formula is =sum(Price)/counta(Product), with Summarize by set to Custom. Every column name in that example sits inside a function, SUM or COUNTA, and that turns out to matter.
Column L of Other results uses =(SUM(Revenue)-SUM(Cost))/SUM(Revenue) with Summarize by Custom. Every row matches the Fixed tab, North at 24.73% and Grand Total at 23.48%. If you need something SUM cannot express, such as average order size with COUNTA, Custom is the mode for it.
Column M has the short formula, =(Revenue-Cost)/Revenue, also on Custom. That is the setup behind the 20.00% for North in the comparison table: one row's margin per region, picked by position in the source. Nothing on screen marks it as wrong, so if you switch a field to Custom, check that every column name in the formula sits inside a function.
Google's page carries one more instruction for custom formulas, in its own terms: field values with spaces get quotations around them. Every header in this copy is a single word, so that case was not tested here.
A check formula beside the pivot table, and the Try it yourself tab
Try it yourself is the Broken tab again, with SUM of Margin % in column J and an empty column L under the header Check: (H-I)/H. Type =ARRAYFORMULA((H2:H6-I2:I6)/H2:H6) into L2. L2:L6 fills with 21.00%, 24.73%, 27.59%, 21.21% and 23.48%, next to the 95.00% and 115.00% in J. The one formula fills all five cells because it is wrapped in ARRAYFORMULA, a function the post on ARRAYFORMULA down a whole column goes through.
Then follow the calculated field steps above in that tab's pivot table: add Profit margin as a calculated field and remove SUM of Margin %. Column J should end up equal to column L and to J2:J6 on the Fixed tab.
The check formula is handy on its own, but it is tied to fixed cells. It reads H2:H6 and I2:I6, so a fifth region would push the Grand Total row below its range. The calculated field is a column of the pivot table itself, so there is no range to keep in step.
| Input | 12 sales, Revenue in C2:C13, Cost in D2:D13; rows East, North, South, West, Grand Total |
|---|---|
| Formula | =(Revenue-Cost)/Revenue (calculated field, Summarize by SUM) |
| Expected | 21.00%, 24.73%, 27.59%, 21.21%, 23.48% |
| Sheets returned | 21.00%, 24.73%, 27.59%, 21.21%, 23.48% Matches expected |
| Checked | 2026-11-11, free personal account |
Take-home copy. Four tabs: Broken (as you see it), Fixed, Try it yourself, Other results. It opens as a copy in your own Drive.