The Table.Unpivot function in Power Query turns the columns you pick into rows. Every value under those columns gets its own row, with the old header in one new column and the value in another.
Every column you didn’t pick stays as it is. So it’s the right choice when you know exactly which columns to unpivot, and anything else in the table (or added to it later) should be left alone.
The catch is that the list of column names you type into the formula also misses new columns you do want unpivoted, like next month’s sales.
In this article, I’ll show you how it works with practical examples, including how to build the list with a rule so those get picked up.
Follow along with the example file
Table.Unpivot Function Examples.xlsx
Table.Unpivot Function Syntax
= Table.Unpivot(table as table, pivotColumns as list, attributeColumn as text, valueColumn as text) as table
- table – the table you want to unpivot. This is usually the previous step, such as
Source. - pivotColumns – a list of the columns you want to unpivot, such as
{"Jan","Feb","Mar"}. Column names are case-sensitive, and each one must exist in the table. - attributeColumn – the name of the new column that holds the old column headers, such as
"Month". - valueColumn – the name of the new column that holds the values that were under those headers, such as
"Sales".
What it returns – a table with every column you didn’t list, followed by the attribute column and the value column. Each source row becomes one row for every listed column that has a value in it.
I’ve tested the Table.Unpivot function in Power Query in Excel for Microsoft 365. It’s also part of the Power Query M language that Power BI uses.
When to Use the Table.Unpivot Function
Use this function when you need to:
- Turn quarter, month, or year columns into rows so you can use the data in a Pivot Table or a chart
- Unpivot only some columns and leave notes, status, or category columns as they are
- Make sure a column added to the source later doesn’t get unpivoted by accident
- Turn a grid that’s mostly empty into a short list of the filled cells
- Pick the columns to unpivot with a rule, like every column whose name starts with “Week”
Example 1: Unpivot Quarter Columns into Rows
Let’s start with a basic example, turning a column for each quarter into rows.
Below is an Excel table named WarehouseShipments with the number of shipments from three warehouses in each quarter, and I want a table with one row for each warehouse and quarter.

To follow along, select any cell in the table and go to Data > From Table/Range to open it in the Power Query Editor. If Power Query adds a Changed Type step, use #"Changed Type" in place of Source in the formulas below.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,{"Q1","Q2","Q3","Q4"},"Quarter","Shipments")
Result: a table with the Warehouse, Quarter, and Shipments columns, and 12 rows

Here, {"Q1","Q2","Q3","Q4"} is the list of columns to unpivot. The Warehouse column isn’t in the list, so it stays as it is and repeats on every row for that warehouse.
The old headers (Q1 to Q4) go into a new column called Quarter, and the numbers under them go into a column called Shipments. Since there are 3 warehouses and 4 quarters, you get 12 rows.
The rows come out warehouse by warehouse, in the same order as the source. You get all four quarters for Dallas first, then all four for Denver, and so on.
The last two arguments are just the names of the new columns, so you can call them whatever you like. If you use "Attribute" and "Value", you get the same names that the Unpivot options in the ribbon give you.
This long shape is what Pivot Tables and charts work best with. If you’d rather do this with the menu options, I’ve covered that in this tutorial on how to unpivot data in Excel.
Example 2: Columns You Don’t List Stay as They Are
The columns you leave out of the list don’t have to be on the left. Table.Unpivot keeps every column you didn’t list, wherever it sits in the table.
Below is an Excel table named TimesheetHours with the hours each employee worked from Monday to Wednesday and their team in the last column, and I want one row for each employee and day.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,{"Mon","Tue","Wed"},"Day","Hours")
Result: a table with the Employee, Team, Day, and Hours columns, and 9 rows

Here, only the three day columns are in the list, so Employee and Team both stay. The columns you keep come first in their original order, and the two new columns (Day and Hours) are always added at the end.
That’s why Team now sits before Day, even though it was the last column in the source.
Every name in the list must exist in the table with exactly that spelling. If someone renames Wed to “Wednesday” in the source, the query stops with the error “The column ‘Wed’ of the table wasn’t found.”
The same thing happens if the case doesn’t match. Writing "mon" in place of "Mon" gives you “The column ‘mon’ of the table wasn’t found.”
The new column names also can’t match a column you’re keeping. If you use "Team" as the attribute column name here, you get the error “The field ‘Team’ already exists in the record.”
Example 3: Leave a Text Column Out of the Unpivot
This example shows the main reason to pick Table.Unpivot. When you name the columns to unpivot, a column that shouldn’t be unpivoted can never end up in your values by mistake.
Below is an Excel table named ProjectHours with the hours logged on three projects over three weeks. A Status column was added at the end later, and I want one row for each project and week with the hours.

First, let’s see what happens if you use the Table.UnpivotOtherColumns function, which works the other way around. You tell it which columns to keep, and it unpivots everything else:
= Table.UnpivotOtherColumns(Source,{"Project"},"Week","Hours")
Result: a table with 12 rows, where the Status text shows up in the Hours column

Here, the formula only says “keep Project”, so Status gets unpivoted along with the weeks. Every project gets an extra row with “Status” in the Week column and “On track” or “Delayed” in the Hours column.
Now Hours has a mix of numbers and text. If you change it to a number type, the cells that held “On track” and “Delayed” turn into errors.
Now use Table.Unpivot instead, and list only the week columns:
= Table.Unpivot(Source,{"Week 1","Week 2","Week 3"},"Week","Hours")
Result: a table with the Project, Status, Week, and Hours columns, and 9 rows

Here, Status isn’t in the list, so it stays as its own column and repeats on every row for that project. The Hours column only has numbers.
The flip side is that the Table.Unpivot formula has a fixed list of weeks. If a Week 4 column is added later, it won’t get unpivoted, and it stays as a separate column.
You could also fix the Status problem with the Table.UnpivotOtherColumns function by adding Status to its list of columns to keep, {"Project","Status"}. That gives the same table, and since it only names the columns to keep, it would unpivot a new Week 4 too.
But any other new column added later, like a second text column, would end up in Hours, just like Status did at the start of this example. Example 7 shows how to pick up new week columns and still leave every other column alone.
Example 4: Turn a Skills Grid into a List
Table.Unpivot skips blank cells. Each blank (null) value in an unpivoted column doesn’t get a row, which is very handy when you have a grid that’s mostly empty.
Below is an Excel table named SkillsMatrix with each employee’s level in Excel, SQL, Python, and Power BI, where a blank cell means they don’t have that skill. I want a list of only the skills each person has.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,{"Excel","SQL","Python","Power BI"},"Skill","Level")
Result: a table with the Employee, Skill, and Level columns, and 7 rows

Here, the grid has 16 cells under the four skill columns, but only 7 of them have a level. The 9 blank cells don’t produce a row, so you get a clean list of who knows what.
Leslie Hill has no skills filled in, so all four of her cells are blank. That means she doesn’t appear in the result at all.
Follow along with the example file
Table.Unpivot Function Examples.xlsx
Example 5: Keep Blank Cells as Zero
Skipping blanks isn’t always what you want. If a blank means zero, dropping it can hide a row you need.
Below is an Excel table named LineRejects with the number of rejected units on three production lines from Monday to Thursday, where a blank cell means no rejects that day. I want a row for every line and every day.

Let’s first see what a plain unpivot gives you:
= Table.Unpivot(Source,{"Mon","Tue","Wed","Thu"},"Day","Rejects")
Result: a table with only 5 rows, and no rows at all for Line C

Here, the blank cells are skipped, just like in the previous example. Line C had no rejects all week, so it disappears from the result, and Line A and Line B lose their zero days.
If you later count the lines or average the daily rejects, you’d get the wrong answer. The fix is to replace the blanks with 0 before you unpivot.
If you added the plain unpivot step above, delete it first (right-click it in the Applied Steps pane and choose Delete), so the next step starts from Source again.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula, which replaces the blank cells in the four day columns with 0:
= Table.ReplaceValue(Source,null,0,Replacer.ReplaceValue,{"Mon","Tue","Wed","Thu"})
Power Query names a step added this way Custom1, so right-click it in the Applied Steps pane, choose Rename, and call it Replaced Value. The next formula refers to it by that name.
Then add another step and unpivot the result of that step:
= Table.Unpivot(#"Replaced Value",{"Mon","Tue","Wed","Thu"},"Day","Rejects")
Result: a table with 12 rows, one for each line and day, with 0 where the cell was blank

Here, the Table.ReplaceValue function turns every null in the four day columns into 0. Now there are no blank cells left, so every cell becomes a row, and Line C shows up with 0 rejects on each day.
Both formulas use the same list of day columns. That way, the replacement covers exactly the columns you unpivot and nothing else.
Example 6: Set the Data Types After Unpivoting
When you unpivot, the old headers always come out as text.
The value column only gets a real data type when every column you unpivot already has that same type. Otherwise, like when the columns have no type yet, it gets the “any” type (shown as ABC123 in the column header).
Below is an Excel table named ClubMembers with the number of members in three clubs for 2024, 2025, and 2026, and I want a table with Year and Members as proper whole numbers.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,{"2024","2025","2026"},"Year","Members")
Rename this step to Unpivoted Columns (right-click Custom1 in the Applied Steps pane and choose Rename), because the next formula refers to it by that name.
Then add another step to set the data type of each column:
= Table.TransformColumnTypes(#"Unpivoted Columns",{{"Club",type text},{"Year",Int64.Type},{"Members",Int64.Type}})
Result: a table with Club as text, and Year and Members as whole numbers

Here, the first step gives you a Year column with the text “2024”, “2025”, and “2026”, because those were column headers.
In the example file, the formula reads the table straight from Source, where the year columns have no data type yet. So Members comes out as any too.
The second step uses the Table.TransformColumnTypes function to make Year and Members whole numbers, so you can sort and filter by year correctly.
If you loaded the table with From Table/Range and kept the Changed Type step, your three year columns are already whole numbers. Then the Members column comes out as a whole number on its own, but Year is still text and still needs converting.
Example 7: Pick the Columns to Unpivot with a Rule
In Example 3, typing the week columns kept Status out, but a Week 4 added later wouldn’t get unpivoted. If you build the list with a rule, you can keep the text column out and still unpivot week columns added later.
Below is an Excel table named AgentTickets with the number of support tickets each agent closed over four weeks and their shift in the last column, and I want one row for each agent and week.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,List.Select(Table.ColumnNames(Source),each Text.StartsWith(_,"Week ")),"Week","Tickets")
Result: a table with the Agent, Shift, Week, and Tickets columns, and 12 rows

Here, Table.ColumnNames(Source) gives the list of all the column names. The List.Select function then keeps only the names where the Text.StartsWith function finds “Week ” (with a space) at the start.
So the list becomes Week 1 to Week 4, and Agent and Shift stay as they are. When a Week 5 column is added, it starts with “Week” too, so it gets unpivoted on the next refresh with no change to the query.
The space after “Week” is there on purpose. Without it, a column like “Weekend Hours” would match too and get unpivoted with the weeks.
The Text.StartsWith function is also case-sensitive. A column named “week 5” (lowercase) wouldn’t match, so it would stay as a separate column.
Table.UnpivotOtherColumns(Source,{"Agent","Shift"},"Week","Tickets") gives the same result here and also picks up new weeks. The difference is what happens when the source changes: that one would unpivot any new column that isn’t Agent or Shift, while the rule above only ever unpivots week columns.
Example 8: Unpivot and Then Total by Month
Once your data is in the long shape, summarizing it is easy. Here, I’ll unpivot a monthly report and then add up each month.
Below is an Excel table named ClinicVisits with the number of patient visits at three clinics from January to March, and I want the total visits for each month.

Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.Unpivot(Source,{"Jan","Feb","Mar"},"Month","Visits")
Rename this step to Unpivoted Columns (right-click Custom1 in the Applied Steps pane and choose Rename), because the next formula refers to it by that name.
Then add another step that groups the rows by month:
= Table.Group(#"Unpivoted Columns",{"Month"},{{"Total Visits",each List.Sum([Visits]),type number}})
Result: a table with 3 rows, Jan 1064, Feb 1048, and Mar 1131

Here, the first step turns the three month columns into a Month column and a Visits column. The second step uses the Table.Group function to put all the rows for each month together and add up their visits.
The months show up in the same order as the columns in the source. Month is text, so if you sort it later, you get Feb, Jan, Mar.
For three months, this may look like more work than adding up each column. But it’s the same two steps for 12 months or 30, and you can group by Clinic in the same way to get each clinic’s total for the quarter.
Other Excel Articles You May Also Like:
- Table.Pivot – Use Table.Pivot in Power Query M to turn row values into columns.
- Table.SelectColumns – Use Table.SelectColumns in Power Query M to keep only the columns you need.
- Table.ExpandTableColumn – Use Table.ExpandTableColumn in Power Query M to expand merged table columns.
- Table.PromoteHeaders – Use Table.PromoteHeaders in Power Query M to make the first row your headers.
- Table.FromColumns – Use Table.FromColumns in Power Query M to build a table from lists.
- Table.ExpandRecordColumn – Use Table.ExpandRecordColumn in Power Query M to turn a record column into columns.
- Table.ReorderColumns – Use Table.ReorderColumns in Power Query M to change column order.
- Table.ColumnNames – Use Table.ColumnNames in Power Query M to list a table’s column names.