Sub topic 9
Ratios and margins: why aggregation order matters
Assume you know how to create a pivot table and how SUM, COUNT, and AVERAGE summarize values. This chapter focuses on calculated fields, especially the difference between adding row-level results and calculating a ratio from already aggregated totals.
A calculated field is a new value created inside a pivot table from source columns. For example, a Profit field can subtract Cost from Revenue.
Two ways to calculate a value
Use this source data as a running example:
Date Region Product Units Revenue Cost
2026-01-05 West Widget 10 250 150
2026-01-19 East Widget 4 100 60
2026-02-02 West Gadget 7 420 245
2026-02-23 South Gadget 3 180 105
2026-03-09 East Gizmo 12 600 420For each row, revenue per unit is Revenue / Units. A pivot table can handle this in two different ways:
- Calculate the ratio for every source row, then summarize those ratios.
- Add all revenue and all units for a group, then divide the totals.
These operations usually produce different results.
Suppose the pivot table groups rows by Product. For the Widget rows:
- Total revenue is
350. - Total units are
14. - Revenue per unit from totals is
350 / 14, or25. - The two row-level ratios are also
25and25, so their average is25.
For the Gadget rows:
- Total revenue is
600. - Total units are
10. - Revenue per unit from totals is
60. - Both row-level ratios are
60.
For all products, however, the results diverge:
- Total revenue is
1550. - Total units are
36. - Revenue per unit from totals is
43.06. - The five row-level ratios are
25,25,60,60, and50. - Their average is
44. - Their sum is
220, which has no useful interpretation.
The sum of ratios is especially dangerous because it can look like a valid number while representing no meaningful business measure.
Add an additive calculated field
Profit is additive because the total profit equals the sum of each row's profit. In the pivot table editor:
- Add
RegionorProductunder Rows. - Add
RevenueandCostunder Values. - Under Values, choose Add, then Calculated field.
- Name the field
Profit. - Enter this formula:
=Revenue - CostWhen the calculated field is summarized by SUM, the overall profit is:
1550 - 980 = 570
This agrees with the sum of row-level profits:
100 + 40 + 175 + 75 + 180 = 570
Additive measures are generally safe to sum because aggregation preserves their meaning.
Use a custom formula for ratios
A margin is a ratio. Gross margin is usually defined as profit divided by revenue:
(Revenue - Cost) / Revenue
To calculate the overall margin correctly, aggregate first:
=SUM(Revenue - Cost) / SUM(Revenue)For revenue per unit, use:
=SUM(Revenue) / SUM(Units)In the pivot editor, add a calculated field, choose Custom as the summary method, and enter the appropriate formula. The exact field names must match the source headers.
For the complete example:
- Total profit is
570. - Total revenue is
1550. - Overall margin is
570 / 1550, or about36.77%. - Revenue per unit is
1550 / 36, or about43.06.
A custom formula that aggregates first gives larger groups more influence when they contain more units or revenue. This is often called a weighted result.
Check the result
Use these checks when a calculated field contains a ratio:
- Confirm that the numerator and denominator are aggregated at the same grouping level.
- Compare the pivot result with a separate
SUMcalculation. - Check whether blank or zero denominators exist.
- Format margins as percentages only after verifying the underlying value.
- Do not sum percentages unless the percentages themselves are meant to be additive.
A custom formula may also fail if a source header is misspelled or if a header contains spaces. Wrap a header with spaces in single quotes:
='Unit Price' * QuantityExercise
The pivot table shows five row-level revenue-per-unit values: 25, 25, 60, 60, and 50. What formula should calculate the overall revenue per unit?
Show answer
Use =SUM(Revenue) / SUM(Units), which produces 1550 / 36, or about 43.06. Do not sum the ratios, and use their average only when an equal-weight row average is the intended measure.