Stop 04 · Power Query TransformationsTopics · 4/11

Removing and Filtering Rows

Part of the Power BI Roadmap

In short

Exports from accounting software love to add report titles, blank lines and grand totals. If those rows sneak into your model, every total in your report is wrong.

You can remove top rows, blank rows and error rows, or filter by value, to keep only the data you actually need.

The jaadu sits cross-legged with a wide steel plate of rice, carefully picking out tiny stones into a small bowl.

Think of it like this

Cleaning rice before cooking

Before cooking, you spread rice on a plate and pick out small stones, husk and broken grains. You do not cook everything and hope. Removing and filtering rows is picking out the stones before they reach the pot.

Watch it happen

Cleaning a raw export, row by row

Title
0
(blank)
1
Header
2
Order 101
3
Order 102
4
(blank)
5
Order 103
6
Grand Total
7

1/5The raw export: a title, a blank row, then the real header and data, plus a grand total at the end.

The big ideas

What you need to know

Remove top and bottom rows

Home, Remove Rows lets you drop a fixed number of rows from the top or bottom.

Filter by value

The column dropdown filters like Excel, but the filter is saved as a step and reapplied on every refresh.

Remove errors

Remove Errors drops rows with errors in selected columns. Use it only after you understand the errors.

Prefer rules over counts

Removing 'top 3 rows' breaks if the export changes. Filtering on a rule like OrderID not null is more robust.

See it in code

Walk through the code

m
1let2    Source = Excel.Workbook(File.Contents("D:\Data\export.xlsx"), null, false),3    Sheet = Source{[Item = "Report", Kind = "Sheet"]}[Data],4    SkipTitle = Table.Skip(Sheet, 2),5    Headers = Table.PromoteHeaders(SkipTitle, [PromoteAllScalars = true]),6    NoBlanks = Table.SelectRows(7        Headers,8        each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))9    ),10    RealOrders = Table.SelectRows(11        NoBlanks,12        each [OrderID] <> null and [OrderID] <> "Grand Total"13    )14in15    RealOrders

1/3Table.Skip removes the first two rows: the report title and a blank line.

Skip the title rows, promote headers, drop fully blank rows and filter out the grand total line.

Save yourself the pain

Common mistakes

Oops

Loading the grand total row along with the data.

Do this instead

Always filter it out. Otherwise every sum in Power BI is exactly double the true value.

Oops

Removing errors without looking at them.

Do this instead

Inspect the errors first. They often point to a real problem, like a new format in the source.

Your mission

Clean an accounting export

~20 min

Quick check

Why is filtering on OrderID usually safer than Remove Bottom Rows (1) for dropping a grand total?

Go deeper

  1. 1Remove header junk rows from an exported report.
  2. 2Filter out test or cancelled records.
  3. 3Use Keep Errors on a copy to inspect what failed.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge