A total row summarizes every record or group in a drilldown table. It helps readers understand the whole before comparing individual dimension combinations. Dimension cells are intentionally blank except for the label “Total.” section 7.5.3 section 7.5.2
Build the row in a few deliberate steps:
- Calculate total metrics from the original granular dataframe, because metric calculations expect raw, non-aggregated data rather than the already grouped table. section 7.5.3
- Create blank values for every selected dimension and place “Total” in the first dimension column. section 7.5.3
- Prepend the total row to the aggregated dataframe with pandas.concat so it appears above the detailed rows. section 7.5.3
- When no dimensions are selected, create a single-row dataframe with an empty dimension column, the “Total” label, and the calculated metrics. section 7.5.3
- Format metric values and shade the row so users can distinguish the summary from the breakdown. section 7.5.3
A drilldown summary
Two product rows show $100,000 and $200,000 in sales. A total row above them shows $300,000, leaves the dimension cells blank, and labels the first dimension “Total.” section 7.5.3
+--------+----------------+--------------+-------------+--------------+----------+-------+ | Gender | Segment | Product name | Total sales | Gross margin | Margin % | ATV | +--------+----------------+--------------+-------------+--------------+----------+-------+ | Total | | | $300,000 | $210,000 | 70% | $20 | | M | Fountain pens | InkStream | $100,000 | $60,000 | 60% | $10 | | M | Fountain pens | RoyalQuill | $200,000 | $150,000 | 75% | $40 | +--------+----------------+--------------+-------------+--------------+----------+-------+
Use the completed table shape to inspect how the total appears above detailed rows and how aggregate values relate to them. section 7.5.3
