7. Data Cleaning A–Z in Power Query
7.17 Unpivot and Pivot in Power Query with Example
Start with a problem
Finance sends monthly sales with one column per month. Rani wants one Month slicer and a line chart; with wide columns she needs a new visual change every month.
Explain simply
Unpivot turns many month columns into two columns: Attribute (Month) and Value (Sales). Pivot does the reverse. Unpivot drops null cells.
Show the data
Before (wide):
| City | Apr-2026 | May-2026 |
|---|---|---|
| Pune | 600 | 250 |
| Nashik | 300 | 500 |
| Kolhapur | null | 450 |
About this data: This table uses columns: City, Apr-2026, May-2026. This table uses columns: City, Month, Sales (₹). This table uses columns: City, Jan, Feb, Mar. This table uses columns: City, Month, Orders. Values shown are the lesson examples already on this page (not a new dataset).
Fictional sample data. Practice file: pq_monthly_sales_wide.csv (source: src/practice/).
Demonstrate
-
Select City › right-click › Unpivot Other Columns.
Your result should look like this:
Rows 5 (Kolhapur Apr null dropped) -
Rename Attribute → Month, Value → Sales. Set Sales to Whole Number.
-
(Optional) Month › Change Type Using Locale › Date, English (India) after replacing
Apr-2026with01-Apr-2026– or add a Month Start column.Your result should look like this:
Month Apr-2026, May-2026 -
To go back: select Month › Transform › Pivot Column › Values: Sales › Sum.
Your result should look like this:
Columns City, Apr-2026, May-2026
Show the result
Your result should look like this (fictional sample):
| City | Month | Sales (₹) |
|---|---|---|
| Pune | Apr-2026 | 600 |
| Pune | May-2026 | 250 |
| Nashik | Apr-2026 | 300 |
| Nashik | May-2026 | 500 |
| Kolhapur | May-2026 | 450 |
| Total | 2,100 |
Explain what happened
Unpivot Other Columns keeps City and unpivots every other column, so June will be included automatically next month.
Explore further
- Unpivot Columns (selected) would miss new months – prefer Unpivot Other Columns.
Detailed reference for this lesson:
Unpivot columns in Power Query with example — in 30 seconds
What: Unpivot turns many month columns into two columns: Month and Value.
Why: Power BI likes long tables. One Month column means one slicer and one line chart for all months.
Tiny example: Jan, Feb and Mar columns become 6 rows with a Month column.
Unpivot columns in Power Query with example — 30 सेकंदात
काय: Unpivot अनेक महिन्यांचे columns दोन columns मध्ये बदलतो: Month आणि Value.
का: Power BI ला लांब tables आवडतात. एक Month column म्हणजे सगळ्या महिन्यांसाठी एक slicer आणि एक line chart.
छोटं उदाहरण: Jan, Feb आणि Mar columns चे Month column असलेल्या 6 rows होतात.
Unpivot columns in Power Query with example — 30 सेकंड में
क्या: Unpivot कई महीनों के columns को दो columns में बदलता है: Month और Value.
क्यों: Power BI को लंबी tables पसंद हैं. एक Month column मतलब सारे महीनों के लिए एक slicer और एक line chart.
छोटा उदाहरण: Jan, Feb और Mar columns से Month column वाली 6 rows बनती हैं.
First look at the data (before, then after):
Same before / after tables as text
Before — Orders typed by month (wide)
| City | Jan | Feb | Mar |
|---|---|---|---|
| Pune | 100 | 120 | 150 |
| Mumbai | 200 | 180 | 210 |
Formula / click path
Select City › Transform › Unpivot Other Columns
Rename Attribute, then Month, Value, then Orders
After — After Unpivot (long)
| City | Month | Orders |
|---|---|---|
| Pune | Jan | 100 |
| Pune | Feb | 120 |
| Pune | Mar | 150 |
| Mumbai | Jan | 200 |
| Mumbai | Feb | 180 |
| Mumbai | Mar | 210 |
Do it step by step:
- Select only the City column.
- Right-click › Unpivot Other Columns. (New month columns next year are then included automatically.)
- Rename Attribute to
Month. - Rename Value to
Orders. Set its type to Whole number.
एक-एक step करून बघा:
- फक्त City column निवडा.
- Right-click › Unpivot Other Columns. (पुढच्या वर्षीचे नवीन महिन्यांचे columns मग आपोआप येतात.)
- Attribute चं नाव
Monthकरा. - Value चं नाव
Ordersकरा. त्याचा type Whole number ठेवा.
एक-एक step करके देखिए:
- सिर्फ़ City column चुनिए.
- Right-click › Unpivot Other Columns. (अगले साल के नए महीनों के columns फिर अपने-आप आ जाते हैं.)
- Attribute का नाम
Monthकीजिए. - Value का नाम
Ordersकीजिए. उसका type Whole number रखिए.
Friends, many Excel reports store data "wide" (one column per month). Power BI works best with "long" (tall) data.
Before (wide)
| City | Jan | Feb | Mar |
|---|---|---|---|
| Pune | 1200 | 1350 | 1500 |
| Nashik | 800 | 860 | 910 |
After (long)
| City | Month | Target Orders |
|---|---|---|
| Pune | Jan | 1200 |
| Pune | Feb | 1350 |
| Pune | Mar | 1500 |
| Nashik | Jan | 800 |
| … | … | … |
(Made-up monthly order targets.)
Steps in Power BI
- Select the column(s) that should stay as they are (City).
- Transform › Unpivot Columns › Unpivot Other Columns.
- Rename Attribute →
Monthand Value →Target Orders. - Pivot (the reverse): select the column whose values should become headers (Month) › Transform › Pivot Column › Values Column:
Target Orders› Advanced options › Aggregate Value Function: Sum or Don't Aggregate › OK.
Unpivoted = Table.UnpivotOtherColumns(Source, {"City"}, "Month", "Target Orders"),
Pivoted = Table.Pivot(Unpivoted, List.Distinct(Unpivoted[Month]), "Month", "Target Orders", List.Sum)
Why Unpivot Other Columns?
Unpivot Other Columns keeps the named columns and unpivots (स्तंभांच्या ओळी करणे) everything else. When April is added next month, it is unpivoted automatically. Unpivot Columns (selected ones only) hard-codes Jan/Feb/Mar and misses April.
Practice task
A target sheet has Area in rows and Blinkit/Amazon Now target orders in two columns. Unpivot it into Area, Platform, Target Orders. Then pivot it back to check your work.
Once you understand Unpivot, you can "fix" many Excel reports. Do the practice task for sure.
Unpivot एकदा समजलं की Excel मधले खूप reports "सुधारता" येतात. Practice task नक्की करा.
Unpivot एक बार समझ आ गया तो Excel की बहुत सी reports "सुधारी" जा सकती हैं. Practice task ज़रूर कीजिए.
Ravindra Bagale's Tip
Friends, many students unpivot by selecting the month columns and clicking Unpivot Columns, so next month's new column is ignored. Select the fixed columns (City, Store) and use Unpivot Other Columns instead, which automatically includes new month columns in future refreshes. This matters for both exams and interviews.
Ravindra Bagale's Tip – मराठी
मित्रांनो, बरेच students month columns select करून Unpivot Columns वर click करतात, त्यामुळे पुढच्या महिन्याचा नवीन column दुर्लक्षित राहतो. त्याऐवजी fixed columns (City, Store) select करून Unpivot Other Columns वापरा, जो पुढच्या refreshes मध्ये नवीन month columns आपोआप घेतो. हे exam आणि interview दोन्हीसाठी important आहे.
Ravindra Bagale's Tip – हिंदी
दोस्तों, बहुत से students month columns select करके Unpivot Columns पर click करते हैं, तो अगले महीने का नया column छूट जाता है. इसकी जगह fixed columns (City, Store) select करके Unpivot Other Columns इस्तेमाल करो, जो आगे के refreshes में नए month columns अपने-आप ले लेता है. यह exam और interview दोनों के लिए ज़रूरी है.
Fix common mistakes
| Wrong result | Reason | Correction |
|---|---|---|
| June missing next month | Used Unpivot Columns on Apr/May only | Use Unpivot Other Columns |
| Kolhapur April missing | Unpivot drops nulls | Expected; replace null with 0 first if you need a row |
| Pivot shows counts | Aggregation Count | Choose Sum |
Practise independently
Practice task
How many rows after unpivot if you first replace Kolhapur's null with 0?
Hints
- 3 cities × 2 months.
Solution
6 rows; total still ₹2,100.
Think like a professional
Long (tall) tables are what Power BI models expect – unpivoting is one of the most valuable cleaning skills.
Revision card
Comparison card