Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Remove Duplicates: Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Removing duplicate rows in Power Query is a straightforward process that cleans your data by eliminating redundant entries, ensuring each record appears only once. This feature is essential for maintaining data integrity when merging tables or analyzing unique customer lists, product inventories, or transaction logs. You can perform this action directly within the Power Query Editor in Excel or Power BI without needing complex formulas or external tools.

What You'll Need

  • A dataset loaded into Power Query (Excel or Power BI).
  • Basic familiarity with the Power Query Editor interface.
  • Microsoft Excel (2016 or later) or Power BI Desktop.

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data or click on an existing query to open it. In Power BI, navigate to Home > Transform Data. Ensure your table is visible in the preview pane.
  2. Select the Relevant Columns: Click on the header of the column you want to check for duplicates. If you need to remove duplicates based on multiple columns (for example, removing rows where both Name and Email are identical), hold down the Ctrl key while clicking each additional column header to select them all.
  3. Locate the Remove Duplicates Command: With the columns selected, look at the ribbon menu at the top of the editor. Navigate to the Home tab. In the "Reduce Rows" group, you will see the button labeled "Remove Duplicates." Note that menu labels may vary slightly depending on your specific version of Excel or Power BI, but the icon usually looks like two overlapping pages with a red minus sign.
  4. Execute the Removal: Click the "Remove Duplicates" button. A dialog box will appear listing the columns you selected. Verify that these are the correct columns for identifying uniqueness. Click OK to confirm.
  5. Review the Results: The preview pane will immediately update to show the cleaned dataset. Check the row count in the bottom left corner of the editor; it should be lower than before if duplicates were found. You can also use the "Keep First" option if you prefer to retain the first instance of a duplicate rather than just deleting all instances indiscriminately.
  6. Close and Apply: Once satisfied with the result, click "Close & Load" in the top-left corner of the Home tab. This saves the transformation step to your query history and updates your main workbook or report with the deduplicated data.

Common Mistakes

One frequent error is selecting the wrong columns for the duplicate check. For instance, if you only select the "ID" column, Power Query will remove any row with a matching ID, even if other details differ. Conversely, if you select too many columns, such as including a timestamp that varies slightly between records, no duplicates will be removed because the combination of values is technically unique every time. Always define what constitutes a "duplicate" in your specific business context before running the tool.

Another common mistake is forgetting to check for trailing spaces or case sensitivity issues. Power Query treats "Apple" and "apple " (with a space) as different strings. If your source data is inconsistent, the remove duplicates function will fail to identify them as the same entry. It is often wise to trim whitespace and convert text to lowercase before attempting to remove duplicates.

Tips

Use the "Group By" feature as an alternative when you need more control over which duplicate to keep. While "Remove Duplicates" simply deletes extra rows, "Group By" allows you to aggregate data, such as keeping the maximum date or summing sales figures for duplicate keys. This is particularly useful when dealing with financial data where you want to consolidate transactions rather than just delete them.

Always inspect your query steps in the "Applied Steps" pane on the right side of the editor. If you realize you made a mistake, you can delete the "Removed Duplicates" step from this list to revert to the previous state without reloading the entire dataset. This non-destructive editing capability is one of Power Query's strongest features.

Troubleshooting

If the "Remove Duplicates" button is greyed out, ensure that you have actually selected at least one column in the preview grid. The command requires a target; it cannot operate on the entire table without specified criteria. Additionally, verify that your data type is consistent. Sometimes, mixed data types (e.g., numbers stored as text in some rows) can cause unexpected behavior during comparison.

If duplicates remain after running the command, check for hidden characters or formatting differences. Use the "Trim" and "Clean" functions under the Transform tab on the relevant text columns before re-running the duplicate removal. Also, consider whether null values are causing issues; Power Query might treat nulls differently depending on the connector used. You may need to replace nulls with a placeholder value if they are interfering with the logic.

Frequently Asked Questions

Does Power Query remove duplicates permanently?

No, it does not alter the original source file. The removal happens in the transformed view within Power Query. Your original CSV, Excel sheet, or database remains untouched. When you refresh the query, the process runs again against the source data.

Can I remove duplicates based on just one column?

Yes, you can select a single column header to base the duplicate removal on. This is useful for lists where one field, like a Customer ID, uniquely identifies a record regardless of other changing attributes.

How do I keep the last duplicate instead of the first?

The standard "Remove Duplicates" feature typically keeps the first occurrence encountered in the current sort order. To keep the last, you would first sort the table descending by the relevant date or index column, then run the remove duplicates command, effectively making the most recent entry the "first" one seen by the engine.

Is there a difference between Excel and Power BI for this task?

The core functionality is identical because both use the M language engine behind the scenes. The user interface steps are nearly the same, though the location of the ribbon tabs might differ slightly between the standalone Excel add-in and the integrated Power BI service.

What happens if my data has errors?

If a column contains errors (red cells), Power Query might skip those rows or throw an error during the duplicate check depending on settings. It is best practice to handle errors using "Replace Errors" or filter them out before attempting to remove duplicates to ensure clean results.