Two tables can hold exactly the same numbers and still be laid out differently. One is easy to chart. The other looks easy to read but fights every chart you try.

The same facts, two layouts

Take a household's spending by category, month by month. One way to lay it out puts each category in its own column:

Month Rent Groceries Utilities …
2023-01 1,509.59 493.55 … …
2023-02 … … … …

That's a wide table. It reads well on a page, like a report. But the category isn't a field anywhere: it's hidden in the column headers.

The other way gives each fact its own row:

Month Category Sum of Amount
2023-01-15 Rent 1,509.59
2023-01-15 Groceries 493.55

That's a tidy table: one row per month and category, one field for the month, one for the category and one for the amount. It's longer, and it's the one charts want.

Why charts want tidy

A chart builds its parts from fields. To draw a line per category, it needs a Category field whose values become the lines. In the tidy table, that field exists, and a new category is just more rows. In the wide table, every category is a separate field, so the chart has to be told about each one, and a new category means a new column that no chart knows about yet.

Tidy tables also keep the rules from the first lesson. Every row is the same kind of thing (one month in one category) and every field holds one kind of fact. In the wide table, the Rent and Groceries columns hold the same kind of fact, an amount, split across several fields.

A stacked area chart of the "Household Expense Breakdown" dataset: 10 Category bands stacked into the total Sum of Amount over Month.
A stacked area chart of the "Household Expense Breakdown" dataset: 10 Category bands stacked into the total Sum of Amount over Month.

How to read this Stacked area chart Try it in the explorer

When side by side is fine

Not every pair of number columns is a wide table. A table of department budgets has one row per department, with an Actual field and a Budget field:

Department Actual Budget
Engineering 815 850
Sales 980 700

Actual and Budget are two different facts about the same department, not one fact split by a category. A chart that compares spending with its budget wants exactly this layout: two measures, side by side.

The test is simple. If the column headers are values of something, like months, years, regions or product names, the table is wide. If they're names of different facts, like Actual and Budget, or Price and Quantity, it's fine as it is.

A variance chart of the "Department Budget vs Actual" dataset: for each Department, how far Actual landed from Budget.
A variance chart of the "Department Budget vs Actual" dataset: for each Department, how far Actual landed from Budget.

How to read this Variance chart (budget vs actual) Try it in the explorer

Turning wide into tidy

Most tools can do this in one step. In Power Query (Power BI and Excel), select the columns that are really values, such as the month columns, and choose Unpivot Columns. Their headers become a new field and their cells become a value field. In Python's pandas, it's melt, and in R it's pivot_longer.

After the unpivot, check the new field's name ("Attribute" by default) and rename it to what it holds, such as Month or Category, so the charts and readers can tell what it is.

Here's the household table from the start of this lesson. Spread it wide and gather it back, and watch the rows and the columns trade places:

Loading the interactive...

Try it

Find a table with one column per month, year or region. Write down what the headers have in common: that's the name of the field they should become. Then unpivot it and check that the row count is the old row count times the number of columns you unpivoted.

The next lesson covers the gaps in a table: what an empty cell means, and what it does to a total, an average and a line.