Sub topic 11
Use groups and calculated fields together
Earlier chapters covered groups (manual, date and numeric) and calculated fields separately. This chapter combines them in one pivot table. It assumes you can build a basic pivot table, you know the Values, Rows and Columns sections of the editor, and you have read the chapters on calculated field syntax and on aggregation order.
The working model
A group and a calculated field act at different stages.
- A group changes how the pivot table labels and bundles source rows. It works on the Rows or Columns fields. It never changes the numbers in the source range.
- A calculated field creates a new measure in the Values section. It reads the source columns by header name.
The pivot table first sorts every source row into a cell, using the row and column groups and any filters. Then it evaluates each value field for the rows that landed in that cell. A calculated field therefore never sees a group. It only sees the set of source rows that the group placed in the cell.
The diagram shows the key point for this chapter. A grand total is evaluated on all remaining rows. It is not the sum of the cells above it. For Sum fields the two give the same number. For ratios they usually differ.
The running example
The source range is in A1:F6 on a sheet named Sales.
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 420Totals for the whole table: 34 units, revenue 1550, cost 980, profit 570.
Add two calculated fields. Both come from earlier chapters.
=Revenue - CostName this one Profit. Keep it summarized by Sum.
=SUM(Revenue) / SUM(Units)Name this one Revenue per unit. Set it to summarize by Custom, so each cell aggregates first and then divides.
Step 1: group the dates
Put Date in Rows. Right-click one date in the pivot table, choose Create pivot date group, then choose Year-Month. If a Month group already exists on another field, use the same option for consistency. The date column must hold real dates. If Sheets right-aligns the values by default, they are dates. If they are left-aligned, they are text, and the date group option will not appear.
Add Profit and Revenue per unit to Values. The expected result:
| Month | Profit | Revenue per unit |
|---|---|---|
| 2026-01 | 140 | 25.00 |
| 2026-02 | 250 | 60.00 |
| 2026-03 | 180 | 50.00 |
| Grand total | 570 | 45.59 |
Here is how Sheets gets these numbers.
- January holds two source rows. Profit is (250 − 150) + (100 − 60) = 140. Revenue per unit is (250 + 100) / (10 + 4) = 350 / 14 = 25.
- The grand total for Revenue per unit is 1550 / 34 = 45.59. The average of the three monthly values would be 45.00, and that is not what Sheets shows.
Step 2: group the regions by hand
Move Region to Columns, or keep Date in Rows and add Region as a second dimension in Columns. Select the East and South labels with Ctrl+click (Cmd+click on Mac), right-click, and choose Create pivot group. Rename the new group label by editing the cell, for example to Non-West. Sheets keeps West as a separate item.
Now the table has two columns of groups, West and Non-West. Totals by region:
| Region group | Profit | Revenue per unit |
|---|---|---|
| West | 275 | 39.41 |
| Non-West | 295 | 46.32 |
| Grand total | 570 | 45.59 |
Check the arithmetic. West has two rows, with units 10 and 7, revenue 250 and 420, and cost 150 and 245. Profit is 275, revenue is 670, units are 17, so revenue per unit is 670 / 17 = 39.41. Non-West has three rows (East twice, South once), with revenue 880 and units 19, so 880 / 19 = 46.32.
Creating the group did not change the Profit grand total, 570. A group only redistributes rows. If a grand total moves after you add a group, something else changed. Look for a filter or a blank row.
Step 3: put both groups in one table
Put the month group in Rows and the region group in Columns. Each cell now holds the rows that fall in that month and region group.
| Month | West profit | Non-West profit | West revenue per unit | Non-West revenue per unit |
|---|---|---|---|---|
| 2026-01 | 100 | 40 | 25.00 | 25.00 |
| 2026-02 | 175 | 75 | 60.00 | 60.00 |
| 2026-03 | blank | 180 | blank | 50.00 |
Empty combinations, like West in March, stay blank. Sheets does not show zero, because no source rows exist for that cell. A blank is not the same as a calculated 0. Keep this in mind if a downstream formula refers to the pivot table.
Why the ratio field needs Custom
Suppose you had written the margin as a per-row calculated field instead.
=(Revenue - Cost) / RevenueWith the field set to Sum, Sheets computes the margin for each source row and then adds those results. For January the two rows give 100/250 = 0.40 and 40/100 = 0.40, so the pivot cell shows 0.80. February shows 0.83, and the Grand total shows about 1.93. These are sums of ratios, which have no meaning as a margin.
The correct figure for the whole table is 570 / 1550 = 0.368. To get it, write the aggregate yourself and set the field to Custom.
=(SUM(Revenue) - SUM(Cost)) / SUM(Revenue)For the Custom option, the cell for January becomes 140 / 350 = 0.40, February becomes 250 / 600 = 0.417, March becomes 180 / 600 = 0.30, and the total becomes 0.368. Format the value as a percentage in the Sheets menu. The pivot editor does not apply a number format for you.
A good rule is that additive measures (profit, units, revenue) can use a per-row formula with Sum. Ratios, averages and anything that divides need a Custom formula that sums first.
Groups change the denominators
Grouping does not alter the formula, but it changes which rows each cell includes. This matters for ratios.
- A margin by month and a margin by quarter are both correct, and they use different row sets.
- A Custom ratio for a group is always the ratio of the group's totals. It is never the average of the ratios of its members.
- If you regroup, the ratio for the new group is recalculated from raw rows. You cannot get it by combining the old cell values.
You can use this to your advantage. Build the ratio once as a Custom field, and regroup the rows and columns as often as you like. Every view stays consistent with the source.
Verify with formulas outside the pivot table
After you combine features, confirm at least three numbers with plain formulas. Put these on a separate sheet or in cells beside the pivot table, not inside it.
=SUM(E2:E6) - SUM(F2:F6)Expected result 570, the Profit grand total.
=SUMIFS(E2:E6, B2:B6, "West") / SUMIFS(D2:D6, B2:B6, "West")Expected result 39.41, the West revenue per unit.
=SUMIFS(E2:E6, A2:A6, ">=" & DATE(2026,1,1), A2:A6, "<" & DATE(2026,2,1))Expected result 350, January revenue.
If all three match, the groups and the fields agree with the source. If one differs, look at the checklist below.
Limitations when you combine the features
- A calculated field cannot use a group. It refers to source column names only. To compute by group, put the group in Rows or Columns and let the pivot table split the rows.
- A calculated field cannot refer to another calculated field. Repeat the full expression instead of referring to a Profit field from a margin field.
- A calculated field appears only in Values. You cannot drop it into Rows, Columns or Filters.
- A manual group is stored by item label. If a new label such as North appears in the source data, it does not join an existing group. It shows up as its own item until you add it to a group.
- A field has one grouping at a time. You cannot apply a manual group and a date group to the same Date field.
- Header names in formulas must match the source headers. If you rename a header, update the calculated field. If the header contains spaces, wrap it in single quotes, as in
='Unit Price' * Quantity.
Troubleshooting checklist
- The date group option is missing. The Date column holds text. Convert it with Format, Number, Date, or with a DATEVALUE formula in a helper column, and check that no cell in the column is blank or holds a text label.
- A ratio column shows values above 1 in the total row. The field is set to Sum with a per-row ratio. Rewrite it with SUM() around each column and set it to Custom.
- A group is missing items after new data arrives. New labels are not added to manual groups. Select the new item and add it to the group.
- The grand total changed after grouping. A filter, a hidden group item or blank source rows changed the row set. Compare with the SUMIFS checks above.
- A calculated field shows an error. Check that every column name matches a header exactly, that a name with spaces is in single quotes, and that no column in the formula is blank.
Exercise
Using the running example, you group Region into West and Non-West and add a field set to Sum with the formula =Revenue / Units. What does the West cell show, and what is the correct revenue per unit for West?
Show answer
Per row, West has 250/10 = 25 and 420/7 = 60, so the Sum field shows 85. The correct value is 670 / 17 = 39.41, which comes from a Custom field with =SUM(Revenue) / SUM(Units).
Exercise
You group Date by Year-Month and add a Custom field =SUM(Revenue) / SUM(Units). The month values are 25, 60 and 50. A colleague says the Grand total should be their average, 45. What does the pivot table show, and why?
Show answer
It shows 45.59 because the total is evaluated on all rows: 1550 / 34. The average of the monthly values weights each month equally, and the months have different unit counts (14, 10 and 12).