Power BI Unpivot Table: Step-by-Step Guide
In this article
To unpivot a table in Power BI, open the Power Query Editor, select the columns you want to keep as rows (for example, month or year columns), then go to the Transform tab and choose Unpivot Columns. This turns wide, cross-tab data into a tidy structure where each row is a single observation, which is what Power BI visuals and DAX expect. You can also unpivot only selected columns or unpivot other columns, depending on which is easier to select. The steps below walk through the full process, including how to avoid the most common mistakes.
What You'll Need
- Power BI Desktop installed and a dataset loaded (Excel, CSV, or another source).
- The table you want to reshape must be in the Power Query Editor. You can open it via Home > Transform data.
- Basic understanding of which columns are identifiers (to keep) and which are values (to unpivot).
Step-by-Step
- Open Power Query Editor. In Power BI Desktop, go to Home > Transform data. The Power Query Editor opens in a separate window. Menu labels can differ slightly by version, device, or region.
- Select the table. In the Queries pane on the left, click the query that contains the wide table you want to reshape. If the data is not loaded yet, use Get Data to connect first.
- Identify the columns to keep. Look at the column headers. Columns that identify a row (such as Product, Region, or ID) should stay as columns. Columns that contain values spread across headers (such as Jan, Feb, Mar, or 2023, 2024) are the ones to unpivot.
- Select the columns to unpivot. Click the first column header you want to unpivot, then hold Ctrl (Windows) or Cmd (Mac) and click the other value columns. To select a contiguous range, click the first header, hold Shift, and click the last header.
- Use Unpivot Columns. With the value columns selected, go to the Transform tab and click Unpivot Columns. If you want to unpivot only the selected columns, use the dropdown arrow on the Unpivot Columns button and choose Unpivot Only Selected Columns. If you prefer to select the identifier columns instead, select those and choose Unpivot Other Columns. Both achieve the same result when used correctly.
- Check the result. Power Query adds two new columns: Attribute (the former column headers) and Value (the cell values). The identifier columns you kept remain as rows. Verify that the row count matches your expectation and that no data is missing.
- Rename the new columns if needed. Double-click the Attribute and Value column headers to give them meaningful names, such as Month and Sales. This makes later DAX and visuals easier to build.
- Set data types. Click the icon in the column header (for example, ABC or 123) and choose the correct type. The Value column is often text after unpivoting, so change it to Whole Number, Decimal Number, or Date as appropriate. The Attribute column is usually text.
- Remove unnecessary columns. If the original table had extra columns you do not need, select them and use Home > Remove Columns. Keep only the identifier, Attribute, and Value columns.
- Apply and close. Click Home > Close & Load to load the reshaped table into the data model. If you want to review first, use Close & Apply. The unpivoted table is now ready for relationships, measures, and visuals.
Common Mistakes
- Unpivoting the wrong columns. If you unpivot identifier columns, you lose the row context. Always keep the columns that identify each row and unpivot the value columns.
- Forgetting to set data types. After unpivoting, the Value column is often text. If you do not change it to a number or date, aggregations and date hierarchies will not work.
- Using Unpivot Other Columns without checking. This option unpivots every column not selected. If new columns are added to the source later, they will be unpivoted automatically, which may or may not be desired. Review the result after each refresh.
- Leaving the Attribute column as text when it should be a date. For example, if the original headers were month names, you may need to convert them or create a date column for time intelligence.
- Not renaming columns. Keeping generic names like Attribute and Value makes reports harder to maintain. Rename them to reflect the data.
- Unpivoting in the report view. Unpivot is a Power Query transformation, not a DAX function. You must do it in the Power Query Editor before loading.
Tips
- Use Unpivot Other Columns when you have many value columns and only a few identifiers; it is faster to select the few identifiers than the many values.
- Before unpivoting, remove any total or subtotal rows from the source. Unpivoting totals creates duplicate or misleading values.
- If your column headers contain a pattern (for example, Jan 2023, Feb 2023), you can split the Attribute column into Month and Year after unpivoting using Split Column > By Delimiter.
- Keep a copy of the original query if you might need the wide format later. You can duplicate the query before unpivoting.
- Use the Advanced Editor to review the M code if the result looks wrong; the Unpivot step appears as Table.UnpivotOtherColumns or Table.Unpivot.
- When refreshing, check that the column names in the source have not changed. Renamed headers can break the unpivot step or cause new columns to appear.
Troubleshooting
If the Unpivot Columns button is greyed out, make sure you have selected at least one column and that the query is not in a state where the step is not allowed (for example, after certain operations). Try selecting the columns again or use Unpivot Other Columns.
If the result has more rows than expected, check for duplicate identifier rows or total rows in the source. Unpivoting multiplies rows by the number of value columns, so a table with 10 identifiers and 12 month columns becomes 120 rows. That is normal.
If values appear as errors after changing the data type, some cells may contain text or blanks. Use Replace Values or filter out errors, or keep the column as text if the values are not purely numeric.
If the Attribute column contains unexpected names, the source headers may have changed. Go back to the source step and verify the column names. You may need to redo the unpivot step.
If the query fails to refresh, check that the source file or database is accessible and that column names have not changed. In Power Query, review the Applied Steps and click the step before the error to see the state of the data.
Frequently Asked Questions
What does unpivot do in Power BI?
Unpivot turns columns into rows. It converts a wide table (many value columns) into a long table with an Attribute column and a Value column, which is easier to analyze and visualize.
Can I unpivot multiple columns at once?
Yes. Select all the value columns you want to unpivot (using Ctrl or Shift) and then click Unpivot Columns. Alternatively, select the identifier columns and use Unpivot Other Columns.
What is the difference between Unpivot Columns and Unpivot Other Columns?
Unpivot Columns unpivots only the selected columns. Unpivot Other Columns unpivots every column that is not selected. The latter is useful when you have many value columns and few identifiers.
Can I undo an unpivot?
Yes. In Power Query, go to the Applied Steps pane and click the X next to the Unpivot step, or press Ctrl+Z. You can also delete the step.
Do I need to unpivot before creating relationships?
Not strictly, but unpivoted tables usually work better for relationships and DAX because they have a clear structure with one value per row. Wide tables often require complex DAX or are unsuitable for certain visuals.
Why are my values showing as text after unpivoting?
Unpivoting often converts values to text because the original columns may have mixed types. Change the data type of the Value column to the correct type (number, date, etc.) using the icon in the column header.