Excel Query Remove Duplicates: A Complete Guide
In this article
To remove duplicates using a query in Excel, you use the Power Query editor to filter out redundant rows based on specific columns, which ensures your source data remains untouched while creating a clean, unique list in a new table. This is achieved by selecting the desired columns in the Power Query editor and choosing the "Remove Duplicates" command from the Home tab or the column header menu.
What You'll Need
- A version of Excel that supports Power Query (Excel 2016 or later, or Excel 2010/2013 with the Power Query add-in installed).
- A dataset organized in a table or a named range.
- A clear understanding of which columns define a "duplicate" (e.g., is a row a duplicate only if every cell matches, or just if the Email address matches?).
Step-by-Step
- Convert your data to a Table: Click anywhere inside your data range. Go to the Insert tab and select Table (or press Ctrl + T). Ensure "My table has headers" is checked. Power Query works most efficiently with official Excel Tables.
- Load data into Power Query: With a cell in your table selected, go to the Data tab on the ribbon. In the Get & Transform Data group, click on "From Table/Range". This will launch the Power Query Editor window, which is a separate interface from the standard Excel grid.
- Identify the Duplicate Criteria: In the Power Query Editor, look at your columns. If you want to remove rows where every single column is identical, you do not need to select specific columns. However, if you only care about duplicates in one specific column (like a Customer ID), click the header of that specific column to highlight it.
- Select Multiple Columns (Optional): If a duplicate is defined by a combination of columns (for example, First Name AND Last Name), hold the Ctrl key and click each of the relevant column headers.
- Execute the Remove Duplicates Command: There are two ways to do this. First, you can right-click on any of the selected column headers and choose "Remove Duplicates" from the context menu. Alternatively, go to the Home tab in the Power Query ribbon, click the "Remove Rows" dropdown menu, and select "Remove Duplicates".
- Verify the Results: Look at the data preview in the editor. Power Query will have stripped away the redundant rows, keeping only the first instance it encountered. Check the "Applied Steps" pane on the right side of the screen; you should see a step labeled "Removed Duplicates".
- Load the Clean Data back to Excel: Once satisfied, click the "Close & Load" button on the Home tab. By default, Excel will create a new worksheet containing a new table with the duplicates removed.
- Refresh the Query: If you add new data to your original source table, you do not need to repeat these steps. Simply go to the Data tab in the main Excel window and click "Refresh All". The query will re-run the removal process on the updated source data automatically.
Common Mistakes
One of the most frequent errors is failing to account for leading or trailing spaces. Excel treats "John Doe" and "John Doe " (with a space at the end) as two different values. To the human eye, they look like duplicates, but to Power Query, they are unique. To fix this, you should apply a "Trim" transformation to your columns before removing duplicates. Right-click the column header, select Transform, and then click Trim.
Another mistake is ignoring case sensitivity. Depending on your settings, Power Query may treat "APPLE" and "apple" as different entries. If your data is inconsistently capitalized, use the Transform > Format > Lowercase or Uppercase option to standardize the text before running the remove duplicates command.
Users also often confuse "Remove Duplicates" with "Group By". While Remove Duplicates simply deletes the extra rows, Group By allows you to aggregate data (like summing total sales for a duplicate customer). If you need to keep a total of the values associated with the duplicates, do not use the Remove Duplicates tool; use the Group By feature instead.
Finally, some users forget to convert their data to a Table first. While you can import data from an external CSV or workbook, trying to run a query on a loose range of cells can lead to errors if the range expands or contracts over time. Using an official Excel Table ensures the query always knows exactly where the data starts and ends.
Tips
To maintain a high-quality dataset, always create a backup of your original data before performing heavy transformations, although Power Query is non-destructive (it doesn't change the source). If you find yourself removing duplicates frequently across different files, consider creating a Power Query Template or saving the query as a connection to reuse the logic.
If you have a massive dataset (hundreds of thousands of rows), removing duplicates in the Power Query Editor is significantly faster and more stable than using the standard "Remove Duplicates" button on the Data tab of the main Excel sheet, which can often cause the application to freeze or crash.
Use the "Applied Steps" pane to your advantage. If you realize you removed duplicates based on the wrong column, you don't have to start over. Simply click the small "X" next to the "Removed Duplicates" step in the Applied Steps list to undo the action and return the data to its previous state.
Combine "Remove Duplicates" with "Remove Empty". Often, datasets contain blank rows that are technically duplicates of each other. By using Remove Rows > Remove Blank Rows before removing duplicates, you ensure your final list is truly clean and contains only valid data entries.
Troubleshooting
If the duplicates are still appearing after you have run the query, the most likely cause is hidden characters or non-printing characters. Use the Transform > Clean function to remove non-printable characters that might be hiding in your cells. This is common when data is exported from old legacy databases or web scrapers.
If you receive an error saying the table cannot be found, check if you renamed the original source table after creating the query. Power Query relies on the table name; if the source table name changes, the query will break. To fix this, go to the Query Settings and update the Source step to point to the new table name.
If the "Close & Load" button is greyed out or not behaving as expected, ensure you are not currently editing a cell within the Power Query preview. Click on a blank area of the editor or a column header to ensure the focus is on the query itself and not a specific data entry point.
If your computer slows down significantly during the process, try reducing the number of columns you are loading into the editor. Use the "Choose Columns" feature to remove unnecessary data before applying the Remove Duplicates transformation. This reduces the memory load on your system.
Frequently Asked Questions
Does this delete the data in my original sheet?
No. Power Query is a transformation engine. It reads the data from your source table and creates a separate, cleaned version of that data in a new location. Your original source remains completely unchanged.
Can I remove duplicates based on only one column but keep all columns?
Yes. In the Power Query Editor, select only the column that contains the duplicates (e.g., the ID column). When you select "Remove Duplicates," Excel will delete the entire row for every duplicate ID it finds, but it will keep all the other column data for the first instance it keeps.
Is Power Query different from the "Remove Duplicates" button on the Data tab?
Yes. The Data tab button is a one-time action that permanently deletes data from your current selection. Power Query creates a repeatable process (a query) that can be refreshed whenever the source data changes.
How do I handle duplicates that have slightly different spelling?
Standard Remove Duplicates cannot handle typos. For this, you would need to use "Fuzzy Matching," which is available in the Merge Queries menu. This allows you to group items that are similar (e.g., "Microsoft" and "Microsoft Inc.") based on a similarity threshold.
Can I use this to find duplicates instead of removing them?
While the specific "Remove Duplicates" tool deletes them, you can find duplicates in Power Query by using the "Group By" feature. Group by the column in question and use the "Count Rows" operation; any row with a count greater than 1 is a duplicate.
Does this work on Mac?
Power Query is available on Excel for Mac in recent versions, though the interface may look slightly different. The core logic of loading data from a table and using the Remove Rows menu remains the same across platforms.