Wide tables that should be long
Values of one variable, such as months or years, are spread across the column headers instead of being stored in a column of their own.
What it looks like
Before
| column A | column B | column C |
|---|---|---|
| region | jan | feb |
| North | 120 | 95 |
| South | 80 | 110 |
After
| column A | column B | column C |
|---|---|---|
| region | month | sales |
| North | jan | 120 |
| North | feb | 95 |
| South | jan | 80 |
| South | feb | 110 |
How it happens
- The layout is natural for reading and for typing: one row per thing, one column per period.
- A new column was added each month, since that was easier than adding rows.
- The table is the output of a pivot, saved as if it were the underlying data.
What it breaks
- Filtering or grouping by the spread-out variable is not possible, because it is not a column.
- Every new period changes the shape of the table, so anything built on it has to be edited.
- Combining files fails when each has a different set of period columns.
How to spot it
- Look for headers that are values instead of names: dates, years, or categories.
- Look for a run of columns that all hold the same kind of measurement.
- Ask whether next month's data would add rows or columns. If columns, the table is wide.
How to fix it
- Identify the columns that identify each row, and the columns that are really one variable spread out.
- Reshape so each row holds one identifier, one value of the spread-out variable, and one measurement.
- Name the two new columns for what they hold, and tidy the former headers into proper values, such as full dates.
- Keep the wide layout for presentation if people prefer it. Wide is a fine way to show data, just a poor way to store it.
- Merged and multi-row headersThe column names are spread over two or more rows, often with merged cells, so no single row names every column.
- One table split across sheetsRows that belong in one table are spread over several sheets or files, one per month, region, or person.
- Multiple values in one cellA single cell holds a list, or two different facts, joined by a comma, slash, or line break.
TermsWide format, Long format, Pivot, Tidy data