Power BI  

Understanding Pivot and Unpivot in Power BI (Power Query) – Concept with Practical Steps

Introduction

In real-world projects, data rarely comes in a perfect format. Sometimes:

  • Months are spread across columns

  • Categories are stored horizontally

  • Data needs restructuring before analysis

This is where Pivot and Unpivot in Power BI (Power Query Editor) become extremely powerful.

In this article, we’ll understand:

  • What Pivot is

  • What Unpivot is

  • Difference between them

  • Real business example

  • Step-by-step practical implementation

  • Performance Tip and Common Mistakes to avoid.

What is Unpivot in Power BI?

Unpivot converts columns into rows.

It transforms wide-format data into normalized (long) format.

Business Scenario Example

You receive sales data like this:

ProductJanFebMar
A100120130
B200210220

This format looks fine in Excel — but for Power BI analysis, it’s not ideal.

We need it like this:

ProductMonthSales
AJan100
AFeb120
AMar130
BJan200
BFeb210
BMar220

This transformation is called Unpivoting.

Practical Steps: How to Unpivot in Power BI

Step 1: Load the CSV File

  1. Open Power BI Desktop

  2. Click Home → Get Data → Text/CSV

  3. Select your file . (Eg:Pivot_Unpivot_Practice_Dataset.csv)

  4. Click Transform Data

Power Query Editor will open.

1_GetData2_TransformData

Step 2: Identify Fixed Columns

In our dataset:

  • Product

  • Region

These should remain unchanged.

The month columns:

  • Jan_2025

  • Feb_2025

  • Mar_2025

These need to be unpivoted.

3_DatasetAnalyse

Step 3: Unpivot the Month Columns

Option 1 (Recommended Method):

  1. Select Product and Region

  2. Go to Transform Tab

  3. Click Unpivot Columns → Unpivot Other Columns

OR

Option 2:

  1. Select Jan_2025, Feb_2025, Mar_2025

  2. Right-click

  3. Choose Unpivot Columns

4_Unpivot Option

Step 4: Rename Columns

After unpivoting, Power BI creates:

  • Attribute → Rename to Month

  • Value → Rename to Sales

5_TableAfterUnpivoting

What is Pivot in Power BI?

Pivot does the opposite of Unpivot.

It converts row values into columns.

It transforms long-format data into wide format.

Example (Reverse Scenario)

If your data is:

ProductMonthSales
AJan100
AFeb120
AMar130

You may want:

ProductJanFebMar
A100120130

This is called Pivoting.

Practical Steps: How to Pivot in Power BI

Step 1: Go Back to Power Query

Click:
Home → Transform Data

Step 2: Select Column to Pivot

Click the Product column.

Step 3: Click Pivot Column

  1. Go to Transform Tab

  2. Click Pivot Column

  3. A popup appears.

6_PowerQueryStepsPivoting - Copy

Step 4: Choose Values Column

In the popup:

  • Values Column → Select Sales

  • Aggregation → Choose Sum (or Don't Aggregate if unique)

  • Click OK.

7_PivotPopUp

Step 5: Result

  • Now your data will be converted into column format.

  • Click Home Tab -> Close & Apply.

8_TableOutput

Pivot vs Unpivot – Key Differences

FeaturePivotUnpivot
ConvertsRows → ColumnsColumns → Rows
Used WhenCreating summary formatNormalizing data
Best ForExport/PresentationData Modeling
Common Use CaseMatrix-style reportsTime Intelligence

Performance Tip

Always perform: Pivot / Unpivot in Power Query - Not using DAX

Because:

  • Power Query transformations happen during data load

  • DAX increases model complexity.

Common Mistakes to avoid

  1. Not analyzing and performing the datatype change step for all columns.
    (eg. Sales column [Datatype is to be set as: Whole Number])

  2. Unpivoting key columns accidentally

  3. Pivoting without selecting proper aggregation (in pop - up)

  4. Forgetting to rename "Attribute" and "Value" columns

  5. Creating relationships before cleaning structure

Conclusion

Pivot and Unpivot are fundamental data transformation techniques in Power BI that help reshape data into analysis-ready formats. Mastering these concepts ensures your data model remains clean, scalable, and optimized for powerful reporting and time intelligence calculations.