Remove Duplicates in Power Query (Keeping the Latest Row)
Power Query's Remove Duplicates is a repeatable query step that re-runs every time you refresh, unlike the Data ribbon's Remove Duplicates button, which is a one-time destructive edit to the worksheet. Both keep the first row they encounter for each duplicate key โ so if you need to keep the most recent row instead, sort by date first, in the query, before removing duplicates.
Quick answer: In Power Query, select the key column(s) > Home > Remove Rows > Remove Duplicates. It keeps the first row per key in the query's current sort order and re-runs on every refresh. To keep the latest row per key, add a Sort step (descending by date) before the Remove Duplicates step โ Power Query has no built-in "keep last" option, so sort order is what controls it.
How is Power Query's dedupe different from the Remove Duplicates button?
The Data ribbon's Remove Duplicates button permanently deletes rows from the worksheet the moment you click OK, with no memory of how it was configured โ run it again next month and you're reconfiguring from scratch. Power Query's Remove Duplicates is one step in a saved query, so it re-applies automatically every time the query refreshes against new source data, and you can see and edit exactly which columns it's checking.
| Data ribbon (Remove Duplicates) | Power Query (Remove Duplicates) | |
|---|---|---|
| Applies to | Data already sitting in the worksheet | Data as it flows through the query |
| Repeatable on refresh | No โ one-time action | Yes โ a saved, re-runnable step |
| Undo | Ctrl+Z immediately, or never after saving/closing | Delete the step in Applied Steps, any time |
| Which occurrence is kept | First occurrence in current sheet order | First occurrence in current query sort order |
How do I remove duplicates in Power Query?
Select the column or columns that define a duplicate (a subset of columns, not necessarily every column), then remove duplicate rows based on just that selection.
1. Select the key column(s), e.g. CustomerID (Ctrl+Click for multiple)
2. Home tab > Remove Rows > Remove Duplicates
(or right-click the column header > Remove Duplicates)
Selecting only the key column(s) โ rather than every column โ matters: if you select all columns, two rows only count as duplicates when every field matches exactly, which misses near-duplicate records that differ in a non-key field like a timestamp.
How do I keep the latest row instead of the first?
Power Query's Remove Duplicates always keeps whichever row it encounters first for a given key, in the query's current row order โ there's no "keep last" checkbox, so you control the outcome entirely by sorting before you dedupe.
1. Sort by the date/timestamp column, Descending
(Home > Sort or click the column's dropdown > Sort Descending)
2. Select the key column(s)
3. Home > Remove Rows > Remove Duplicates
Because the newest row for each key now comes first,
Remove Duplicates keeps it and discards the older rows.
Alternative approach for more control: use Group By on the key column with an aggregation of "Max" on the date column to find each key's latest date, then merge that back to pull the full row โ more steps, but explicit about what "latest" means if there are ties.
Does Power Query's dedupe compare case-sensitively?
Yes โ like Power Query's Merge, the default duplicate comparison is case-sensitive, so "Acme" and "ACME" are treated as different values and both survive. Normalize with Text.Upper or Text.Lower on the key column first (Transform > Format > UPPERCASE/lowercase) if the source data has inconsistent casing.
Common mistakes when deduping in Power Query
Most dedupe mistakes come from not controlling sort order before removing duplicates, or from doing the cleanup somewhere that won't survive the next refresh.
- Removing duplicates before sorting: if you need the latest row per key, the Sort step must come before Remove Duplicates in Applied Steps, not after.
- Selecting every column instead of just the key: misses duplicates that differ only in a non-key field (e.g. an updated status column).
- Assuming it's case-insensitive: "Acme" and "ACME" both survive unless you normalize case first.
- Using the worksheet's Remove Duplicates button on a query-fed table: the next refresh reintroduces the duplicates, since the fix lived outside the query. Do the dedupe inside the query instead so it survives refreshes.
For the worksheet-level Remove Duplicates button and formula-based approaches without Power Query, see remove duplicates in Excel. For combining tables before deduping, see Power Query Merge.
Pro Tip: Add a Group By step instead of Remove Duplicates when you also want a count of how many duplicate rows existed per key โ Group By with a "Count Rows" aggregation gives you that audit trail for free, which Remove Duplicates silently discards.
โ Back to Excel Tips