In this article
The same totals, with two different compositions
These are two authored ledgers of four records each, with amounts in CNY. Each is defined as the complete set for this exercise, containing only North, South and categories X and Y, with additive amounts. They are not actual sales, accounting revenue or store-performance data. Ledger A contains North/X/100, North/Y/50, South/X/50 and South/Y/100. Ledger B contains North/X/75 twice and South/Y/75 twice.
Both produce store totals of North 150 and South 150, and category totals of X 150 and Y 150. Yet X’s share within North is 100 / 150, about 66.7%, in A and 150 / 150, or 100%, in B. Both total reports are accurate, but they cannot select between those answers.
We actually executed store, category and joint grouping queries in isolated SQLite and obtained the table below. This checks these teaching specimens, not software performance or real business behavior. Download the eight source rows and the joint-grouping SQL to reproduce it. The dataset column separates A from B; do not combine the two alternative situations into one business total.
| Store / Category | Ledger A (CNY) | Ledger B (CNY) |
|---|---|---|
| North / X | 100 | 150 |
| North / Y | 50 | 0 |
| South / X | 50 | 0 |
| South / Y | 100 | 150 |
An aggregate has already selected a question
Store totals serve a useful purpose: quickly read, rank or compare amounts over an agreed scope. They turn many records into a few legible values. Aggregation is doing its job. Trouble arises when a table answering store totals is treated as material that still answers category composition within a store.
SQLite’s GROUP BY documentation explains how grouped results are calculated. Grouping fields determine which records are collected together. If the output retains only store and its amount total, it no longer contains the relationship between category and individual records. Two different inputs producing the same output demonstrate why that output cannot uniquely reconstruct the input.
Combining the two accurate marginal reports does not repair this. Category totals constrain each category’s overall amount, but do not say where it falls among stores. Returning to a source retaining the joint relationship, or obtaining an authorized cross-group summary, supplies the additional information.
A different layout does not restore lost grain
A matrix with North and South as columns and X and Y as rows can retain all four joint amounts. A four-row Store, Category, Amount table can express the same information. Wide versus long is a layout choice; detail versus aggregation concerns grain. They should not be confused.
Hadley Wickham’s Tidy Data paper uses variables, observations and observational units to explain table structure, including different arrangements of the same data. That distinction is useful here: decide what a row represents before choosing its columns. Making a two-row store-total table long still leaves only those two totals.
When grouping choices will change, a source organized around observations and fields is often easier to reuse, with a presentation view selected afterward. Microsoft’s PivotTable instructions also distinguish column-based source data with one header row from the PivotTable created from it. This article does not report an Excel UI test; it checks the documented method and the SQLite teaching calculations.
Our existing month-column and paired-metric unpivot case deals with putting surviving month, units and amount values into the right records. This essay concerns an earlier decision: which relationships should remain available for a different class of question.
Choose the questions before the retained grain
List the follow-up questions the team is authorized to answer, then describe the relationships each requires. That turns “keep the detail” into specific field and grain requirements. Continuing the teaching example:
| Follow-up question | Sufficient material | What it still cannot answer |
|---|---|---|
| What is each store’s registered total? | A trustworthy store-level total | The X/Y mix inside each store |
| What is each store’s X/Y composition? | A trustworthy Store × Category aggregate | What one original record says |
| Why does a particular record have this amount? | A locatable source record and necessary supporting evidence | Business causes not supplied by the material |
Give the source and the presentation different jobs
If Store × Category is the full requirement, the four joint amounts answer this essay’s follow-up question. It does not require customer names, addresses or every original order. If record-level checks are also needed, retain the relevant identifiers and source relationships within access and retention rules, or agree that an authorized owner will supply them when required.
In an Excel handoff, a source sheet with Store, Category and Amount can hold the authorized cross-group aggregate, while another sheet presents store totals. The three columns could instead be a separate controlled CSV for later grouping. Add authorized record identifiers only if record-level checks require them. A recipient of a workbook can also obtain its source sheet; store the layers separately when access differs. Hiding a sheet is not access control.
For sources from several files, use the header mapping and source reconciliation guide to establish fields and inclusion. Changing a metric definition between weeks is the separate problem discussed in reporting definitions and historical series; retaining more rows does not make different definitions comparable.
A concrete requirement could read: “Display store totals in this edition; retain an authorized source supporting Store × Category analysis; do not promise order-level tracing.” That is more actionable than “keep the detail.” It also lets the next question start with material already available rather than immediately returning to an export button.
Key Takeaways
Retain authorized data at the grain needed for follow-up questions, separately from the presentation view. Store totals and category totals alone cannot determine their joint distribution; changing wide data to long cannot recover an aggregated-away relationship. If only fixed cross-group questions are needed, that aggregate layer may suffice without retaining every underlying record.
- Two ledgers can have identical store totals and category totals but different category mixes within each store.Read the supporting section: The same totals, with two different compositions
- Wide and long describe layout. Grain determines which relationships remain; changing layout cannot restore lost information.Read the supporting section: A different layout does not restore lost grain
- List authorized follow-up questions before choosing fields or aggregate layers. Keeping detail need not mean retaining everything.Read the supporting section: Choose the questions before the retained grain



