Sub topic 4
Promoting Headers and Removing Junk Rows
What this chapter covers and what it assumes
This chapter assumes you can connect Power BI Desktop to a CSV or Excel file and open the Power Query Editor. You should also know what the Applied Steps pane is and how to read a formula bar entry. If not, review the earlier chapters on the editor and on Applied Steps.
Many files are not tables when they arrive. They carry a report title, a "generated on" line, blank spacer rows, and sometimes subtotals or footers. Power Query often guesses that the first row holds the data, so the real column names end up as a data row and the columns are called Column1, Column2, and so on. This chapter shows how to find those problems, fix them in the right order, and avoid the mistakes that make the fix break on the next refresh.
The usual shape of a messy file
Consider an export like this one:
Quarterly Sales Report
Generated 2026-11-01
OrderID,OrderDate,Amount
1001,2026-10-03,120
1002,2026-10-04,80
Total,,200A table needs one header row followed by data rows. This file has two title lines and a blank line above the header, and a total line below the data. All of these must go before the table is usable. The goal is a table where every row is an order and every column name is a real name.
Promote headers
Promoting headers means taking the values in the first row and using them as column names. In the editor, choose Home > Use First Row as Headers. The editor adds a Promoted Headers step.
The step in M looks like this:
Table.PromoteHeaders(Source, [PromoteAllScalars = true])The PromoteAllScalars = true option tells Power Query to promote every scalar value in the first row, including numbers and dates, and convert it to text for the column name. Without it, only text values are promoted, and a numeric header such as 2026 would stay as a data value. When a header row holds years or other numbers, this option matters.
Two details to know:
- The editor may promote headers for you. For CSV and Excel sources it often adds a
Promoted Headersstep and aChanged Typestep automatically. Check the Applied Steps pane before you add your own, or you will promote a row that is already data. - Promoting headers a second time turns your first data row into column names. If your column names suddenly look like
1001and120, you have promoted twice. Delete the extra step.
There is also Use Headers as First Row. It reverses the operation by turning the column names back into the first data row. It is useful when the editor promoted the wrong row, and it is also the way to inspect what was promoted.
Remove junk rows from the top
Promoting headers only works on the first row, so remove the junk above the header first. The relevant command is Home > Remove Rows > Remove Top Rows. Enter the number of rows to remove. For the sample file above, that is three: the title, the "generated" line, and the blank line.
In M this is:
Table.Skip(Source, 3)The editor shows the generated step as Table.Skip, not Table.RemoveFirstN, in current versions. The two behave the same here: they discard the first rows and keep the rest.
Do the steps in this order:
- Remove the top rows that sit above the header.
- Promote the first remaining row to headers.
- Remove junk from the bottom and the middle.
- Set data types.
The order matters. If you promote headers first, the title line becomes the column name, and you cannot get the real header back without undoing the step.
A caution about CSV files
For a CSV, the title lines can confuse the parser. Power Query decides how many columns the file has from the data it reads. A title line with no commas looks like a one-column row. In many cases the import still works, but the extra rows may be padded with nulls. If the column count looks wrong, check the Csv.Document step. You can set the Columns option explicitly, or you can switch the source to read the file as plain text lines and split it yourself. For most files, though, removing top rows is enough.
Remove junk rows from the bottom
Footers such as totals and notes need removing too. Use Remove Rows > Remove Bottom Rows, which generates Table.RemoveLastN:
Table.RemoveLastN(PromotedHeaders, 1)The number is fixed. If next month's file has a two-line footer, the step removes the wrong amount. A fixed count works only when the layout never changes. Prefer a filter when the footer has a recognizable pattern, as in the next section.
Remove junk rows by content
Rows in the middle of the data, such as repeated header lines from paged exports or subtotal lines, cannot be removed by position. Filter them by value instead.
Open the filter menu on a column and uncheck the values you do not want, or use Text Filters > Does Not Equal or Does Not Begin With. For the total line in our sample, filter OrderID so it does not equal Total:
Table.SelectRows(PromotedHeaders, each [OrderID] <> "Total")Filtering by content survives changes in row count. It fails only when the label itself changes, for example from Total to Grand Total. In that case use a pattern such as Text.StartsWith or filter on a rule like "OrderID is not a number" after the type is set.
Remove blank rows
Choose Remove Rows > Remove Blank Rows to drop rows where every column is empty or null. Be careful with the word "blank". A cell that holds a space is not null and not empty, so the row survives. Clean the text first, as covered in the chapter on cleaning text, if you see rows that look empty but remain. A row with a value in even one column is not removed.
A related command is Remove Rows > Remove Errors, which is covered in a later chapter. Do not use it to hide structural problems.
Keep or remove a range of rows
Keep Top Rows, Keep Bottom Rows, and Keep Range of Rows keep a block instead of removing one. These are useful when you want a fixed window, such as a block of rows starting at row 5. They share the same weakness as the fixed counts above: they depend on the layout staying the same.
Fixing the sample file
Putting it together, the query for the sample file after loading it as a CSV looks like this:
let
Source = Csv.Document(File.Contents("C:\Data\sales.csv"), [Delimiter = ",", Encoding = 65001]),
RemovedTopRows = Table.Skip(Source, 3),
PromotedHeaders = Table.PromoteHeaders(RemovedTopRows, [PromoteAllScalars = true]),
RemovedTotal = Table.SelectRows(PromotedHeaders, each [OrderID] <> "Total"),
ChangedType = Table.TransformColumnTypes(RemovedTotal, {{"OrderID", Int64.Type}, {"OrderDate", type date}, {"Amount", type number}}, "en-US")
in
ChangedTypeNotice that the type change comes last. The Total row has text in OrderID, and converting that column to an integer before removing it would produce an error value. Removing junk before typing keeps the error count low.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Columns are named Column1, Column2 | Headers were never promoted | Use First Row as Headers |
| Column names look like data values | Headers promoted twice | Delete the second promote step |
| Column name is a report title | Top rows not removed first | Undo promote, remove top rows, promote again |
| Step breaks after a new file arrives | Fixed row count no longer matches | Filter by content instead of by position |
| Rows look empty but stay | Cells hold spaces, not nulls | Trim text, then remove blank rows |
| Error in a column after typing | Junk row still present | Remove junk before changing the type |
Duplicate and renamed column names
If the header row contains the same name twice, Power Query appends .1, .2, and so on to make them unique. If a later refresh finds a renamed column, any step that refers to the old name fails with "The column 'X' of the table wasn't found." Promoting headers and then renaming in a separate step makes that dependency visible in Applied Steps. A failing step tells you where the file changed.
Exercises
Exercise
A file has a three-line title block, then the header row, then data. In what order should you remove the title lines and promote headers, and why?
Show answer
Remove the top three rows first, then promote headers. If you promote first, the first title line becomes the column names, and the real header row stays in the data.
Exercise
Your query removes the last two rows to drop a footer. Next month the footer has three lines. What happens, and what is a more robust approach?
Show answer
The step removes only two lines, so one footer line stays in the data. A more robust approach is to filter by content, for example with Table.SelectRows to drop rows whose first column starts with a footer label.
Exercise
After promoting headers, your columns are named 1001 and 120. What probably happened, and how do you fix it?
Show answer
Headers were promoted twice, so the first data row became the column names. Delete the second Promoted Headers step, or the first one if the source already promotes headers.