Power Query course · Lesson 6 of 17
Filtering, sorting and removing rows and columns
Remove header junk and blank rows, fill down group labels, filter text, numbers and dates, remove duplicates and sort, in a way that survives refresh.
Exports rarely start with clean headers in row 1. They come with report titles, print dates, blank lines, subtotal rows and a grand total at the bottom. In a worksheet you delete those rows by hand each time. In Power Query you describe which kind of row to remove, and the description keeps working when the file has 300 rows this month and 4,000 next month. This lesson covers removing rows and columns, filtering, de-duplicating and sorting.
A report-style export
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Regional sales report | |||
| 2 | Period: March 2026 | |||
| 3 | ||||
| 4 | Region | Rep | Product | Units |
| 5 | North | K. Olsen | Router X2 | 14 |
| 6 | K. Olsen | Switch 8P | 6 | |
| 7 | L. Weber | Router X2 | 9 | |
| 8 | South | P. Rossi | Access Point | 21 |
Before: three junk lines, headers in row 4, and the Region label printed only on the first row of each group.
Removing top rows and promoting headers
- Choose Home › Remove Rows › Remove Top Rows, enter
3, and click OK. The header line is now the first row. - Choose Home › Use First Row as Headers (also on Transform). The values become column names.
- Power Query adds a Changed Type step; check the icons as you learned in The Power Query Editor: steps, formula bar and data types.
Remove Top Rows is safe only if the number of junk lines never changes. If it does, a more robust method is to filter on content instead, for example to skip rows until the one whose first column is Region. That needs a little M, which you will meet in The M language: let, steps, lists, records, tables and each:
= Table.Skip(Source, each [Column1] <> "Region")Fill Down: repeat group labels
The Region column has a value only on the first row of each group. Select it and choose Transform › Fill › Down. Every null is replaced by the value above it. Fill › Up does the opposite, which is useful when a label is printed at the end of a group, as in some accounting reports.
null in Replace With.| A | B | C | D | |
|---|---|---|---|---|
| 1 | Region | Rep | Product | Units |
| 2 | North | K. Olsen | Router X2 | 14 |
| 3 | North | K. Olsen | Switch 8P | 6 |
| 4 | North | L. Weber | Router X2 | 9 |
| 5 | South | P. Rossi | Access Point | 21 |
After: junk removed, headers promoted, Region filled down. Each row now stands on its own and can be filtered or pivoted.
Removing blank rows, bottom rows and errors
Home › Remove Rows has six options:
| Option | Removes |
|---|---|
| Remove Top Rows | A fixed number of rows at the start |
| Remove Bottom Rows | A fixed number of rows at the end, such as a Total line |
| Remove Alternate Rows | A repeating pattern: first row to remove, number to remove, number to keep |
| Remove Duplicates | Rows whose values in the selected columns appeared before |
| Remove Blank Rows | Rows where every column is null or empty |
| Remove Errors | Rows with an error in the selected columns |
The mirror image is Home › Keep Rows: Keep Top Rows, Keep Bottom Rows, Keep Range of Rows, Keep Duplicates and Keep Errors. Keep Duplicates is a great auditing tool: run it on an invoice number column to see which invoices were exported twice.
Total in the first column's filter. If the export one day comes without a total, a fixed Remove Bottom Rows would delete a real sale.Filtering with the header drop-down
Click the arrow in a column header. You get a sort section, a list of values with tick boxes and a type-specific filter menu:
- Text Filters: Equals, Does Not Equal, Begins With, Does Not Begin With, Ends With, Does Not End With, Contains, Does Not Contain.
- Number Filters: Equals, Does Not Equal, Greater Than, Greater Than Or Equal To, Less Than, Less Than Or Equal To, Between.
- Date Filters: Equals, Before, After, Between, In the Next…, In the Previous…, Is Earliest, Is Latest, Is Not Earliest, Is Not Latest, and calendar filters such as Year, Quarter, Month, Week and Day.
- Advanced filter dialogs (choose Advanced in the filter window) combine several conditions with And / Or, even across columns.
For example, to keep only shipped and invoiced orders from an ERP export, a deliberate condition is clearer than ticking boxes:
= Table.SelectRows(#"Changed Type", each [Status] = "Shipped" or [Status] = "Invoiced")Relative date filters
Date Filters › In the Previous… with 3 months keeps rows from the last three complete months relative to today, every time the query refreshes. Use it for rolling reports. Note that Power Query uses the clock of the computer that refreshes, and that the generated condition (Date.IsInPreviousNMonths) excludes the current, incomplete month.
Removing and choosing columns
- Home › Remove Columns deletes the selected columns.
- Home › Remove Columns › Remove Other Columns keeps only the selected ones.
- Home › Choose Columns opens a tick list of all columns, handy for wide exports with 60 columns.
Which is safer? Remove Other Columns and Choose Columns list the columns to keep, so a new column added to the source later is ignored. Remove Columns lists the columns to drop, so a new source column flows through to your output. Pick the behaviour you want; for stable reports, keeping a defined list is usually better. Either way, a step fails if a column it names disappears from the source.
Removing duplicates
Select the column or columns that define a duplicate, then choose Home › Remove Rows › Remove Duplicates. Power Query keeps the first occurrence and removes the later ones. To de-duplicate whole rows, select all columns first (Ctrl+A [Cmd+A on Mac] in the preview).
| A | B | C | |
|---|---|---|---|
| 1 | Name | Signed up | |
| 2 | [email protected] | Ana Silva | 2026-01-12 |
| 3 | [email protected] | Ana Silva | 2026-02-03 |
| 4 | [email protected] | Ben Ito | 2026-01-20 |
| 5 | [email protected] | Ana Silva | 2026-03-01 |
Before: a newsletter list with the same person three times, once in capitals.
| A | B | C | |
|---|---|---|---|
| 1 | Name | Signed up | |
| 2 | [email protected] | Ana Silva | 2026-01-12 |
| 3 | [email protected] | Ben Ito | 2026-01-20 |
After: Format › lowercase on Email, then Remove Duplicates on Email. Without the lowercase step, the capitalised row would survive.
Signed up descending first. Because Power Query may not keep the sort order when it removes duplicates on large sources, add Table.Buffer around the sorted step or use Group By with a Max (Group By: totals, counts and the All Rows trick) when the choice matters.Sorting
Click a header arrow and choose Sort Ascending or Sort Descending, or use the buttons on Home. To sort by several columns, sort the first column, then the second: Power Query adds them to the same step, in that order of priority. The formula looks like this:
= Table.Sort(#"Filled Down", {{"Region", Order.Ascending}, {"Units", Order.Descending}})Check yourself
1. The Region label appears only on the first row of each group. Which command fixes it?
Fill Down copies the value above into null cells.
2. Why is filtering out 'Total' safer than Remove Bottom Rows 1?
A content-based filter does not delete a real row when the layout changes.
3. Power Query's Remove Duplicates treats [email protected] and [email protected] as…
It is case-sensitive; lowercase the column first.
4. Which column command ignores new columns that appear in the source later?
Remove Other Columns records the list of columns to keep.
5. What does Fill Down do with empty text values?
Replace empty values with null first.