Unpivot columns into rows
Budgets, forecasts and many exports are laid out for reading: one row per department, one column per month, January to December across the page. That layout is easy to read and hard to analyse. You cannot filter on a month, chart a trend or build a pivot table by quarter when the months are column headers. Unpivoting turns those columns into rows. Here is what it does, and how to do it in a few clicks.
Wide and long, with an example
A wide table has one column per month:
| Department | Jan | Feb | Mar |
|---|---|---|---|
| Sales | 120 | 135 | 128 |
| Marketing | 40 | 42 | 55 |
The same data, long, has a column for the month and a column for the value, one row per department and month:
Sales, Jan, 120 · Sales, Feb, 135 · Sales, Mar, 128 · Marketing, Jan, 40 · and so on.
Twelve month columns become twelve rows per department. The long table is the one tools expect: a pivot table, a chart over time, a filter on one month, a join with another table by month all need the month to be a value, not a header.
Why not just keep the wide layout?
- Adding a month means adding a column, and every formula and chart must be extended.
- A total per quarter needs a formula that knows which columns belong to which quarter.
- A pivot table cannot group the columns January to March into Q1.
- Combining two years of reports doubles the number of columns instead of the number of rows.
Unpivot in Excel
Excel has no unpivot command in the sheet. The tool is Power Query: load the table, select the columns that stay (the department), then Transform › Unpivot Other Columns, and load the result back. It works well, it is refreshable, and the result is subject to the usual 1,048,576-row limit when loaded into a sheet. A file of 100,000 rows and 12 months becomes 1.2 million rows, which no longer fits.
Unpivot in Big Sheets
Big Sheets is a spreadsheet for files of several million rows, in your browser. Unpivot is a command on the selected columns, like sorting.
- Open the file.
- If the group label only appears on the first row of each group, select that column and choose Fill down empty cells.
- If a cell holds two facts, such as “Alice Martin, Lyon”, split it with Split column and a comma.
- Click the first month’s column letter, then Shift+click the last one.
- Right-click and choose Unpivot columns into rows.
- Name the two new columns, for example month and budget, and confirm.
- Check the row count: rows before × number of columns unpivoted.
Every step can be undone with Ctrl+Z, and each is recorded, so next month’s report can go through the same transformation with one replay.
After unpivoting
- Turn the month into a real date if you need to group by quarter or year: for example a calculated column that builds the date from the month name and the year.
- Build a pivot table: department in Rows, month in Columns, budget in Values. You are back to the wide layout, but now it is a view you can change in a click.
- Chart the trend: a line chart with the month on the axis.
- Combine several years by stacking the long tables, which only adds rows.
A typical case: the yearly budget file
Finance sends a budget with one row per department and cost centre, and twelve month columns. You want actuals against budget by quarter. The actuals arrive as a long export from the accounting system: one row per entry, with a date.
Unpivot the budget into department, month and budget; turn the month into a date; then a pivot table of each table by quarter, or a join of the two on department and month, puts budget and actuals side by side. The wide file could not be compared with the long one; the long one can be compared with anything.
Common pitfalls
- A total column among the months: unpivoting it would count everything twice. Delete it first.
- Merged cells in the header: export the report without merged cells, or rename the columns after import.
- Blank cells in the month columns become rows with an empty value. Filter them out if they mean “no data”.
Everything runs in your browser, and the file stays on your device. Try it on the sample data first, no account needed.
Try it on your own file
Open it in Big Sheets: no sign-up, and your file never leaves this browser.
One plan: €29 incl. VAT per month, everything included, cancel any time. See pricing
Questions
- What is the opposite of unpivoting?
- A pivot: a pivot table turns the values of a column back into columns.
- Can I unpivot more than a million rows?
- Yes in Big Sheets, as long as the result fits in your device’s memory; it is tested on files up to 5 million rows.
- Can I undo an unpivot?
- Yes, with Ctrl+Z, like every step.