Excel Power Query: Remove Duplicate Rows Step-by-Step
In this article
Removing duplicate rows in Excel using Power Query is the most reliable way to clean large datasets without altering your original source files. Unlike the standard "Remove Duplicates" feature on the Data tab, which permanently deletes data from your worksheet, Power Query creates a repeatable transformation step. This means you can refresh your report at any time, and the duplicates will be automatically removed again based on the logic you defined, ensuring your data remains consistent and accurate for analysis.
What You'll Need
- A dataset in Excel or connected via a supported source (CSV, Database, etc.).
- Excel 2016 or later (Power Query is built-in; earlier versions require an add-in).
- Basic familiarity with the Excel ribbon interface.
- Note: Menu labels may vary slightly depending on your specific version of Excel and operating system.
Step-by-Step
- Select Your Data: Click inside your table or range of data in the Excel worksheet. If your data is not formatted as a Table, go to the Insert tab and click Table, then confirm the range and check "My table has headers."
- Load into Power Query: With the table selected, go to the Data tab on the ribbon. In the "Get & Transform Data" group, click From Table/Range. This opens the Power Query Editor window, displaying your data in a preview pane.
- Identify Duplicate Criteria: Decide whether you want to remove duplicates based on all columns or just specific ones. To remove rows that are identical across every column, leave no columns selected. To remove duplicates based on specific fields (e.g., only if the "Email" address matches), click the header of that column to select it. Hold Ctrl to select multiple non-adjacent columns if needed.
- Apply the Removal: Navigate to the Home tab within the Power Query Editor. In the "Reduce Rows" group, click Remove Rows, then select Remove Duplicates. A dialog box will appear confirming which columns are being used to identify duplicates. Click OK.
- Verify the Results: The preview pane will update immediately to show the cleaned data. Check the row count displayed in the bottom left corner of the editor to see how many rows were removed. Ensure the remaining data looks correct.
- Close and Load: Once satisfied, go to the Home tab and click Close & Load. This returns you to Excel and places the cleaned data into a new worksheet or pivot table cache, leaving your original source data untouched.
Common Mistakes
The most frequent error is selecting the wrong columns for the duplicate check. For example, removing duplicates based solely on "Name" might delete distinct records for two different people with the same name. Always verify which columns define a unique record in your context. Another common mistake is forgetting that Power Query treats blank cells and null values differently than Excel formulas; ensure your source data is consistent regarding empty entries before loading.
Tips
You can chain this step with other transformations. For instance, you might first filter out errors, then trim whitespace, and finally remove duplicates. The order matters: trimming spaces before checking for duplicates ensures that "John Doe " and "John Doe" are recognized as the same entry. Additionally, if you need to keep the first occurrence but remove subsequent ones, note that Power Query’s default behavior keeps the first instance encountered in the current sort order. If your data isn't sorted, consider adding a "Sort Ascending" step on a date or ID column before removing duplicates to control which record is retained.
Troubleshooting
If the row count does not decrease as expected, check for hidden characters. Sometimes, data imported from web sources contains non-breaking spaces or special Unicode characters that look identical but are technically different. Use the "Trim" and "Clean" functions in the Transform tab before removing duplicates. If you accidentally removed too many rows, simply click the gear icon next to the "Removed Duplicates" step in the Applied Steps pane on the right. Here, you can change the columns used for identification without deleting and recreating the step. If the query fails to load due to memory issues, try filtering your data to a smaller subset first to test the logic.
Frequently Asked Questions
Does Power Query modify my original Excel file?
No. Power Query reads the source data and applies transformations in a separate engine. Your original table or CSV file remains unchanged unless you explicitly overwrite it, which is not the default behavior.
Can I undo a duplicate removal after closing the editor?
Yes. You can reopen the Power Query Editor by going to the Data tab and clicking Queries & Connections, then double-clicking your query. From there, you can delete or modify the "Removed Duplicates" step in the Applied Steps list.
How do I handle case-sensitive duplicates?
By default, Power Query is case-insensitive for text comparisons in some contexts but strict in others depending on the source. To force case sensitivity, you may need to create a custom column that converts text to uppercase or lowercase before running the remove duplicates step, ensuring consistent matching.
Why did my duplicate removal fail on numeric data?
Ensure your columns are typed correctly. If a column containing numbers is typed as "Text," "123" and " 123" (with a space) will be treated as different values. Change the column type to Whole Number or Decimal Number in the Home tab before removing duplicates.