Sub topic 4
Promoting headers and removing junk rows
This chapter assumes you can open the Power Query Editor and read the Applied Steps pane. It also assumes you know what a column data type is. Here you fix the top and bottom of a table before you touch any values.
Why the order matters
Exported files often carry extra content. You may see a report title, a "Generated on" line, blank spacer rows, or a Total row at the bottom. Power Query reads all of it as data. Until the real header row is promoted, your columns are named Column1, Column2, and so on.
Fix the structure first. Type detection and cleaning steps work on the wrong rows if junk is still present.
Removing top rows
On the Home tab, choose Remove Rows, then Remove Top Rows. Enter how many rows to drop. The editor writes a Table.Skip step. Count only the rows above the real header.
Promoting headers
Choose Use First Row as Headers. The editor writes Table.PromoteHeaders. Its PromoteAllScalars = true option turns numbers and dates in the header row into text, so they can serve as column names.
The editor often adds a Changed Type step right after promoting. This step can lock in types that are wrong, so check it.
Removing blank and footer rows
- Remove Blank Rows deletes rows where every column is empty or null.
- Remove Bottom Rows deletes a fixed number of rows from the end, such as a Total row.
- Keep/Remove Rows and column filters can drop rows by value, such as any row where
OrderIDis "Total".
Worked example
This query builds a small messy table in M, so you can paste it into the Advanced Editor and run it.
let
Source = #table(
{"Column1", "Column2", "Column3"},
{
{"Sales export", null, null},
{"Generated 2026-11-01", null, null},
{"OrderID", "OrderDate", "Amount"},
{"1001", "2026-10-02", "120.50"},
{null, null, null},
{"1002", "2026-10-03", "75"},
{"Total", null, "195.50"}
}
),
RemovedTopRows = Table.Skip(Source, 2),
PromotedHeaders = Table.PromoteHeaders(RemovedTopRows, [PromoteAllScalars = true]),
RemovedBlankRows = Table.SelectRows(PromotedHeaders, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
RemovedBottomRows = Table.RemoveLastN(RemovedBlankRows, 1),
ChangedType = Table.TransformColumnTypes(RemovedBottomRows, {{"OrderID", Int64.Type}, {"OrderDate", type date}, {"Amount", type number}}, "en-US")
in
ChangedTypeThe result has two data rows with the headers OrderID, OrderDate, and Amount. The Total row is removed before the type change. If it stayed, converting "Total" to a whole number would produce an error.
Common errors
- Removing the wrong number of rows. Check the preview after each step. Click an earlier step in Applied Steps to see the table at that point.
- Promoting headers twice. The second promotion turns your first data row into column names.
- Hard-coded row counts.
Remove Top Rowswith a fixed count breaks if next month's export has three title lines instead of two. For unstable files, filter by value instead. - Blank text that is not null. A cell holding spaces is not empty, so Remove Blank Rows skips it. Trim the text first (a later chapter covers this).
Exercise
A file has three title lines, then the header row, then data. After you choose Remove Top Rows and enter 3, what should be your next step, and why not set types first?
Show answer
Use First Row as Headers. The header row is now the top row, so promoting it gives the columns real names. Setting types first would apply them to a table that still has the wrong top row, which can lock in wrong types or produce errors.