Power BI Lesson 19 – Transform Rows & Columns | Dataplexa
Power Query · Lesson 19

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.

Raw source table — before any transformations
Column1 Column2 Column3 Column4 Column5
Sales Report 2024
Exported by Finance
OrderIDOrderDateCustomerNameRevenueStatus
10012024-01-05Alice Brown1200Shipped
10022024-01-18Bob Singh850Delivered
10032024-02-03Carol Lee430Processing
10042024-02-14Alice Brown95Shipped
10052024-03-07David Kim1540Delivered
End of report
Problems: 2 junk header rows · real headers buried in row 3 · 1 junk footer row · generic column names · Revenue stored as text

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.

Before — Remove Top Rows (2)
Sales Report 2024
Exported by Finance
OrderIDOrderDate
10012024-01-05
10022024-01-18
After — junk rows gone
OrderIDOrderDate
10012024-01-05
10022024-01-18
10032024-02-03
How: Home tab → Remove Rows → Remove Top Rows → enter number of rows to remove → OK. Also available via right-click on a row number in the preview.

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.

Before — generic names, real headers in row 1
Column1Column2Column3
OrderIDOrderDateRevenue
10012024-01-051200
10022024-01-18850
After — real column names promoted
OrderIDOrderDateRevenue
10012024-01-051200
10022024-01-18850
10032024-02-03430
How: Home tab → Use First Row as Headers. Or Transform tab → Use First Row as Headers. Power BI also offers this automatically the first time you connect to many flat file sources.

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.

How: Home tab → Remove Rows → Remove Bottom Rows → enter count. For variable footers, use Home → Remove Rows → Remove Blank Rows, or use the column filter arrow and deselect the footer value.

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.

Column filter dropdown — Status column
Filter type
Text Filters ▾
Search values
🔍 Search...
OK
Cancel
Text Filters options:
Equals / Does Not Equal
Begins With / Does Not Begin With
Ends With / Does Not End With
Contains / Does Not Contain
Custom Filter — combine two conditions with AND / OR

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.

Before — CustomerID has duplicates
CustomerIDCustomerName
C101Alice Brown
C101Alice Brown
C102Bob Singh
C102Bob Singh
After — one row per CustomerID
CustomerIDCustomerName
C101Alice Brown
C102Bob Singh
Important: Remove Duplicates keeps the first occurrence and discards all others silently. If your data has two different rows for the same CustomerID with different names (a real data quality problem), the second row is dropped without warning. Always investigate why duplicates exist before removing them.

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
Column1OrderIDDescriptive — tells you what it contains
order dateOrderDatePascalCase, no spaces — cleaner in DAX formulas
rev ($)RevenueNo special characters — parentheses break some formulas
CUST_IDCustomerIDConsistent 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.

Recommended order: key/ID columns first → date columns → dimension text columns → numeric measures last. This matches how most people read a table and how visuals default to displaying columns.

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.

Remove Columns
Select one or more columns you want to delete → right-click → Remove. Hold Ctrl to select multiple columns at once. Best when you have a few specific columns to drop from a large table.
Remove Other Columns
Select the columns you want to keep → right-click → Remove Other Columns. All unselected columns are deleted. Best when a source has 40 columns and you only need 6 — select the 6 and remove everything else.

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.

Before — wide table (wrong shape for Power BI)
RegionJanFebMar
North12,40013,10015,200
South8,9009,40010,100
Month is in column headers — cannot use as a date slicer
After — tall table (correct shape)
RegionMonthRevenue
NorthJan12,400
NorthFeb13,100
NorthMar15,200
SouthJan8,900
SouthFeb9,400
Month is now a column value — works as a slicer and axis
How: Select the columns that contain the values you want to keep as identifiers (Region in this example) → Transform tab → Unpivot Columns → Unpivot Other Columns. The month column headers become rows in an "Attribute" column. Rename "Attribute" to "Month" and "Value" to "Revenue".

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.

Before — tall key-value pair table
SettingValue
CurrencyUSD
RegionNorth America
FiscalYearStartApril
After — settings as columns (pivot on Setting)
CurrencyRegionFiscalYearStart
USDNorth AmericaApril
How: Select the column whose unique values will become new column headers (Setting) → Transform tab → Pivot Column → choose the Values Column (Value) → choose aggregation (Don't Aggregate for text, Sum/Average for numbers).

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.

Before — metrics as rows
MetricValue
Revenue83,450
Orders1,204
Customers342
After — metrics as columns
RevenueOrdersCustomers
83,4501,204342

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(...)
Clean table after all 8 steps
OrderID OrderDate CustomerName Revenue Status
10012024-01-05Alice Brown1,200Shipped
10022024-01-18Bob Singh850Delivered
10032024-02-03Carol Lee430Processing
10042024-02-14Alice Brown95Shipped
10052024-03-07David Kim1,540Delivered
Junk rows removed · real headers promoted · correct types · cancelled excluded · clean column names · logical column order

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.