Power BI Course
Transforming Rows and Columns
Cleaning data is mostly about two things: fixing what is wrong with your rows and fixing what is wrong with your columns. This lesson covers every row and column transformation you will use regularly — removing, reordering, renaming, pivoting, unpivoting, transposing, and promoting headers — with before-and-after examples for each one so you know exactly when to reach for each tool.
The Working Dataset
All examples in this lesson start from the same messy raw table — exactly the kind of thing you get when someone exports data from a legacy system or pastes rows together from multiple spreadsheets.
| Column1 | Column2 | Column3 | Column4 | Column5 |
|---|---|---|---|---|
| Sales Report 2024 | ||||
| Exported by Finance | ||||
| OrderID | OrderDate | CustomerName | Revenue | Status |
| 1001 | 2024-01-05 | Alice Brown | 1200 | Shipped |
| 1002 | 2024-01-18 | Bob Singh | 850 | Delivered |
| 1003 | 2024-02-03 | Carol Lee | 430 | Processing |
| 1004 | 2024-02-14 | Alice Brown | 95 | Shipped |
| 1005 | 2024-03-07 | David Kim | 1540 | Delivered |
| End of report |
Row Transformations
Remove Top Rows
When a source file has junk rows above the real data — report titles, export metadata, blank spacers — Remove Top Rows strips them off. You specify exactly how many rows from the top to delete.
| Sales Report 2024 | |
| Exported by Finance | |
| OrderID | OrderDate |
| 1001 | 2024-01-05 |
| 1002 | 2024-01-18 |
| OrderID | OrderDate |
| 1001 | 2024-01-05 |
| 1002 | 2024-01-18 |
| 1003 | 2024-02-03 |
Use First Row as Headers
After removing the junk rows, the real column headers are sitting in the first data row — still labelled Column1, Column2, etc. Use First Row as Headers promotes that row into actual column names and removes it from the data.
| Column1 | Column2 | Column3 |
|---|---|---|
| OrderID | OrderDate | Revenue |
| 1001 | 2024-01-05 | 1200 |
| 1002 | 2024-01-18 | 850 |
| OrderID | OrderDate | Revenue |
|---|---|---|
| 1001 | 2024-01-05 | 1200 |
| 1002 | 2024-01-18 | 850 |
| 1003 | 2024-02-03 | 430 |
Remove Bottom Rows
Report footers, totals rows, and "End of file" markers live at the bottom. Remove Bottom Rows strips them the same way Remove Top Rows does from the top. The challenge is knowing exactly how many rows to remove — if the number changes between refreshes, the step breaks. Use Remove Rows → Remove Blank Rows or filter by a specific value instead when the count is unpredictable.
Filter Rows
Row filtering keeps only the rows that match a condition. It is the most frequently used row operation in real-world data cleaning — excluding cancelled orders, restricting to a date range, removing test records, or keeping only a specific region.
Remove Duplicates
Remove Duplicates keeps only the first occurrence of each unique combination of values in the selected columns. Select one column and it deduplicates by that column alone. Select multiple columns and it deduplicates by the combined key across all selected columns.
| CustomerID | CustomerName |
|---|---|
| C101 | Alice Brown |
| C101 | Alice Brown |
| C102 | Bob Singh |
| C102 | Bob Singh |
| CustomerID | CustomerName |
|---|---|
| C101 | Alice Brown |
| C102 | Bob Singh |
Column Transformations
Rename Columns
Column names in reports and DAX measures are visible to report viewers. Clean, consistent names make everything downstream easier. Double-click any column header to rename it inline — faster than using the ribbon.
| Bad name (before) | Good name (after) | Why |
|---|---|---|
| Column1 | OrderID | Descriptive — tells you what it contains |
| order date | OrderDate | PascalCase, no spaces — cleaner in DAX formulas |
| rev ($) | Revenue | No special characters — parentheses break some formulas |
| CUST_ID | CustomerID | Consistent casing with other ID columns in the model |
Reorder Columns
The order of columns in Power Query determines the default column order in the Data pane and in Table visuals. Drag column headers left or right in the preview to reorder them — each drag records a "Reordered Columns" step. Alternatively, right-click a header → Move → To Beginning / To End / Left / Right.
Remove Columns / Remove Other Columns
Loading unnecessary columns into the model wastes memory and slows refresh. Remove any column that will never be used in a visual, relationship, or measure.
Pivot and Unpivot
Pivot and Unpivot are among the most powerful — and most confusing — transformations in Power Query. Understanding when to use each one is essential because real-world data frequently arrives in the wrong shape for Power BI's column-based model.
Unpivot — Wide to Tall
A wide table has one column per time period or category — common in Excel budgets and financial exports. Power BI needs tall tables — one row per measurement. Unpivot converts wide to tall automatically.
| Region | Jan | Feb | Mar |
|---|---|---|---|
| North | 12,400 | 13,100 | 15,200 |
| South | 8,900 | 9,400 | 10,100 |
| Region | Month | Revenue |
|---|---|---|
| North | Jan | 12,400 |
| North | Feb | 13,100 |
| North | Mar | 15,200 |
| South | Jan | 8,900 |
| South | Feb | 9,400 |
Pivot — Tall to Wide
Pivot is the reverse — it takes unique values from a column and turns them into new column headers, aggregating the corresponding values. Use it to reshape a tall summary table into a cross-tab format for display, or to create lookup columns from a key-value pair table.
| Setting | Value |
|---|---|
| Currency | USD |
| Region | North America |
| FiscalYearStart | April |
| Currency | Region | FiscalYearStart |
|---|---|---|
| USD | North America | April |
Transpose
Transpose rotates the entire table — rows become columns and columns become rows. It is used rarely but is essential when source data arrives with dates or categories as row headers instead of column headers.
| Metric | Value |
|---|---|
| Revenue | 83,450 |
| Orders | 1,204 |
| Customers | 342 |
| Revenue | Orders | Customers |
|---|---|---|
| 83,450 | 1,204 | 342 |
Putting It All Together — Full Cleaning Sequence
Full Applied Steps to clean the raw Sales Report table:
Step 1 — Remove Top Rows (2)
Removes "Sales Report 2024" and "Exported by Finance" rows
M: Table.Skip(Source, 2)
Step 2 — Use First Row as Headers
Promotes row 3 (OrderID, OrderDate...) to column names
M: Table.PromoteHeaders(#"Removed Top Rows", ...)
Step 3 — Changed Type
Sets OrderID → Int64, OrderDate → Date, Revenue → Decimal
M: Table.TransformColumnTypes(...)
Step 4 — Remove Bottom Rows (1)
Removes "End of report" footer row
M: Table.RemoveLastN(#"Changed Type", 1)
Step 5 — Remove Blank Rows
Removes any fully empty rows in the middle of the data
M: Table.SelectRows(... each not List.IsEmpty(...))
Step 6 — Filter Rows — Status
Keeps only Shipped, Delivered, Processing (excludes Cancelled)
M: Table.SelectRows(... each [Status] <> "Cancelled")
Step 7 — Renamed Columns
Renames any remaining generic names to clean descriptive names
M: Table.RenameColumns(...)
Step 8 — Reordered Columns
Puts ID columns first, dates second, measures last
M: Table.ReorderColumns(...)
| OrderID | OrderDate | CustomerName | Revenue | Status |
|---|---|---|---|---|
| 1001 | 2024-01-05 | Alice Brown | 1,200 | Shipped |
| 1002 | 2024-01-18 | Bob Singh | 850 | Delivered |
| 1003 | 2024-02-03 | Carol Lee | 430 | Processing |
| 1004 | 2024-02-14 | Alice Brown | 95 | Shipped |
| 1005 | 2024-03-07 | David Kim | 1,540 | Delivered |
Teacher's Note: Unpivot is the transformation that surprises beginners most. When you receive a sales budget spreadsheet from Finance with months as column headers — January, February, March... December — your instinct might be to keep it that way and build twelve separate measures. Do not. Unpivot it immediately. One Month column and one Revenue column gives you a slicer, a line chart axis, and a relationship to a Calendar table for free. Wide tables feel intuitive in Excel but they are the enemy of a clean Power BI model.
Practice
Practice 1 of 3
A source CSV file has two junk rows at the top (a title row and a blank row), followed by the real column headers in row 3. The correct sequence of steps is: Home → Remove Rows → Remove ___ Rows (2), then Transform → Use First Row as Headers.
Practice 2 of 3
You receive a budget table with columns: Department, Jan, Feb, Mar, Apr. To reshape it so each month becomes a row value instead of a column header — making it usable as a time axis — you apply the ___ Columns transformation.
Practice 3 of 3
You have a table with 35 columns and need to keep only 5 of them. Rather than removing 30 columns one by one, you select the 5 columns you want to keep, right-click, and choose Remove ___ Columns.
Lesson Quiz
Quiz 1 of 3
A source Excel file has a title row and a date-stamp row before the real headers. Next month a third metadata row will be added. Using Remove Top Rows with a fixed count of 2 will break. What is the more robust approach?
Quiz 2 of 3
You apply Remove Duplicates to the CustomerID column of your Customers table. Afterwards you notice the table went from 120 rows to 95 rows. What should you investigate before accepting this result?
Quiz 3 of 3
A colleague gives you a table with columns: Product, Q1, Q2, Q3, Q4 — where Q1–Q4 contain quarterly revenue figures. You want to create a line chart showing Revenue by Quarter. What transformation do you apply first?
Next up — Lesson 20 covers Grouping and Aggregation — how to use Group By to summarise rows, create running totals, and build aggregated summary tables directly inside Power Query without writing a single DAX measure.