Stop 04 · Power Query TransformationsTopics · 5/11

Removing Duplicates and Replacing Nulls

Part of the Power BI Roadmap

In short

Duplicate orders inflate revenue, and blank cells break groupings. Both are among the most common data problems, and Power Query fixes them in a couple of clicks if you know the traps.

Remove Duplicates keeps the first row for each unique value in the selected columns, and Replace Values or Fill Down handles nulls left by exports and merged cells.

The jaadu in a teacher's shawl strikes out a repeated line in a big register and fills empty boxes with a pen.

Think of it like this

The class attendance register

A teacher finds Aarav's name written twice on the register, so she strikes one out (remove duplicates). Some rows say only 'ditto' under the class column, so she fills in the class from the row above (fill down). Every gap and repeat gets fixed before the totals are counted.

Watch it happen

Region column from a merged-cell export

North
0
null
1
null
2
South
3
null
4
West
5

1/3Merged cells in Excel leave only the first row of each group filled.

The big ideas

What you need to know

Duplicates by chosen columns

Select OrderID and Remove Duplicates to keep one row per order. Select all columns to remove only fully identical rows.

Which row is kept?

It keeps the first row it meets. If you need the latest version, sort first and use Table.Buffer so the order is respected.

Fill Down for merged cells

Fills nulls with the value above, perfect for exports where a category is written only once per block.

Replace nulls with care

Replace a null discount with 0 only if missing really means zero. Otherwise leave it null.

See it in code

Walk through the code

m
1let2    Source = Orders,3    FilledRegion = Table.FillDown(Source, {"Region"}),4    NoDiscountNulls = Table.ReplaceValue(5        FilledRegion, null, 0, Replacer.ReplaceValue, {"Discount"}6    ),7    Latest = Table.Buffer(8        Table.Sort(NoDiscountNulls, {{"UpdatedAt", Order.Descending}})9    ),10    OnePerOrder = Table.Distinct(Latest, {"OrderID"})11in12    OnePerOrder

1/4Fill Down on Region fixes the gaps left by merged cells.

Fill merged-cell regions, treat a missing discount as zero, then keep the most recently updated row for each OrderID.

Save yourself the pain

Common mistakes

Oops

Removing duplicates across all columns and assuming each order now appears once.

Do this instead

Two rows of the same order with different timestamps are not identical. Select only the key column, OrderID.

Oops

Replacing every null in every column with 0.

Do this instead

Decide per column. A null age or rating replaced with 0 drags averages down.

Your mission

De-duplicate a CRM export

~25 min

Quick check

Remove Duplicates on CustomerID keeps which row for each customer?

Go deeper

  1. 1Remove duplicate customer rows based on Customer ID only.
  2. 2Use Fill Down on a column where values appear only in the first row of a group.
  3. 3Decide whether a null should become 0, 'Unknown' or stay blank.

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