Yes, Power Query’s Remove Duplicates command keeps the first occurrence of each duplicate row and removes subsequent ones. This is the default behavior in both the Power Query Editor in Excel and Power BI, and it applies to entire rows or to selected columns, depending on what you select before clicking the button.
What Remove Duplicates Actually Does
When you click Remove Duplicates in Power Query, it scans the selected columns (or the entire table if no columns are selected) and compares each row against all previous rows. The first time a unique combination of values appears, that row is kept. Any later row that exactly matches that combination is deleted. The order of rows in your data is preserved—Power Query does not sort or shuffle anything before removing duplicates, so “first” means the first row in the current data order.
This is different from Excel’s native Remove Duplicates feature on the Data tab, which also keeps the first occurrence but operates on a static worksheet range. Power Query’s version is part of a query, so it re-runs every time you refresh the data, making it ideal for recurring data imports.
How to Remove Duplicates in Power Query (Step by Step)
- Load your data into Power Query: In Excel, select your data range or table, then go to Data > From Table/Range (or Data > Get Data for external sources). In Power BI, use Transform Data from the Home tab.
- In the Power Query Editor, select the column(s) you want to check for duplicates. To select multiple columns, hold Ctrl and click each column header.
- On the Home tab, click Remove Rows > Remove Duplicates.
- Power Query removes all rows that have duplicate values in the selected columns, keeping the first occurrence.
- Click Close & Load (Excel) or Close & Apply (Power BI) to load the cleaned data.
If you want to keep the last occurrence instead, you must sort your data in reverse order before removing duplicates, or use a grouping approach with the Table.Distinct function and a custom comparer.
How to Choose Which Columns to Deduplicate On
The key decision is whether you want to remove duplicates based on the entire row or just a few key columns. For example, if you have a customer table with columns CustomerID, Name, and Email, and you select only CustomerID, Power Query will keep the first row for each unique ID, even if the email differs. If you select all three columns, it only removes rows where all three values match exactly.
Common use cases:
- Deduplicate by ID: Select only the ID column to keep one record per ID.
- Deduplicate by full row: Select all columns to remove exact duplicate rows.
- Deduplicate by multiple keys: Select several columns, like
OrderIDandProductID, to keep one line per combination.
Note that Power Query treats null values as equal to each other. So if two rows both have null in the selected column, they are considered duplicates and only the first is kept.
Common Problems and Misconceptions
One frequent misconception is that Power Query removes duplicates based on the entire row even when you select a single column. That is not true—the selection determines the duplicate criteria. Another issue is that the Remove Duplicates button is grayed out when you have no columns selected. You must select at least one column, or click the table icon in the top-left corner to select all columns.
Another problem occurs when your data has leading/trailing spaces or different data types (e.g., text vs. number). Power Query does not trim spaces automatically, so "123" and " 123" are considered different. Use Transform > Format > Trim before removing duplicates if needed.
Also, be aware that Remove Duplicates is case-sensitive for text. So "Apple" and "apple" are treated as distinct. If you want case-insensitive deduplication, you need to transform the column to lowercase or uppercase first.
Power Query vs. Excel’s Native Remove Duplicates
Excel’s native Data > Remove Duplicates works on a worksheet range and permanently deletes rows. Power Query’s version is non-destructive—the original data source remains untouched, and the deduplication is applied only in the query output. This makes Power Query the safer choice when you need to re-run the process on updated data.
Another difference: Excel’s native feature has a dialog where you check columns to include. Power Query does not have a dialog—you simply select columns beforehand. Also, Excel’s native feature keeps the first row based on the current sort order, just like Power Query, but it does not give you a preview of how many duplicates will be removed before you click OK.
If you are working with a one-time cleanup on a static dataset, Excel’s native feature is faster. If you are building a repeatable data transformation pipeline, Power Query is the better choice.
Alternatives: Group By and Table.Distinct
For more control, you can use the Group By feature to aggregate duplicates instead of simply removing them. For example, you might want to sum sales for duplicate order lines. To do that, select the key columns, then go to Transform > Group By, and choose an aggregation like Sum or Average for the value column.
If you are comfortable with the M language, you can also use the Table.Distinct function directly in the Advanced Editor. The syntax is:
Table.Distinct(Source, {"ColumnName"})
This returns a table with duplicate rows removed based on the specified column(s). It behaves the same as the UI button—keeping the first occurrence. You can also add a second argument to specify a custom comparer, but that is rarely needed.
Another alternative is to use Remove Rows > Remove Blank Rows if your duplicates are actually blank rows, but that is a different operation.
Frequently Asked Questions
Does Power Query remove duplicates keep the first or last row?
It keeps the first occurrence based on the current order of rows. If you want the last, sort the data in reverse order before applying Remove Duplicates.
Can I remove duplicates based on multiple columns?
Yes, select multiple columns (hold Ctrl and click headers) before clicking Remove Duplicates. It will only remove rows where all selected columns match.
Why is my Remove Duplicates button grayed out?
You need to select at least one column. Click the column header, or click the small table icon at the top-left of the data preview to select all columns.
Does Remove Duplicates work on merged cells?
No, Power Query does not support merged cells. You must unpivot or fill down values before deduplicating.
Will Remove Duplicates change my original data?
No, Power Query only affects the query output. Your original source data remains unchanged.
Can I undo Remove Duplicates after I’ve loaded the data?
In the Power Query Editor, you can remove the step by clicking the ‘X’ next to the step in the Applied Steps pane. After loading to Excel, you can refresh the query to revert, but if you’ve made manual changes to the loaded data, those are separate.
Related
- Hot Air Balloon Worksheet: How It Works & Printable Guide
- How to Update R Version (Windows, Mac, Linux)
- Modify Windows Shortcuts: Full Guide to Remapping Keys
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How Replace Works in Excel: Find and ReplaceIn Excel, “replace” can mean the REPLACE function, which swaps characters at a specified position in text, or…
- Excel Heat Map by ZIP Code: Setup, Limits, and FixesYes. In Microsoft Excel for Microsoft 365 on Windows, you can shade ZIP-code regions with a filled map:…
- Excel PivotTable Percentages: How to Calculate ThemTo calculate percentages in an Excel PivotTable, right-click a value, choose Show Values As, and select % of…
- Excel Shortcut to Insert a Copied Row Without Replacing DataIn Excel for Microsoft 365 on Windows, copy the source row with Ctrl+C, select the destination row header,…
- Clear Cache in Microsoft Outlook: Windows, Mac & MobileTo clear cache in the Microsoft Outlook app, use the method for your device: repair or reset new…
- Temporary Filter in Google Sheets: How to Use OneTo apply a temporary filter in Google Sheets without changing what collaborators see, open the sheet in a…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.