---
title: Best Practice To Trim Before Removing Duplicates or Merging In Power Query Editor
description: Matt Peterson explains the best way to trim before removing duplicates or merging in Power Query Editor.
---

[Pragmatic Works Nerd News ](https://pragmaticworks.com/blog)

# [Best Practice To Trim Before Removing Duplicates or Merging In Power Query Editor](https://pragmaticworks.com/blog/trim-before-removing-duplicates-power-query)

 Written by [Matt Peterson](https://pragmaticworks.com/blog/author/matt-peterson) | Feb 09, 2021

In last week’s blog, I wrote and did a video about how to remove duplicate records and keep the most recent entry as long as a date column was part of the data source.  I came across the scenario while giving training on Power BI with my company Pragmatic Works.  See the video below:

This week, while doing another two-day training I came across a different scenario from a follow-up conversation from day 1.  I had explained how to **remove duplicate records** and one of the students started working on a Power BI project she has for her company.  On day 2 the student informed me that her remove duplicates step was not working.  I said that is odd and I asked to see the data.  In one of her table visuals, I could see that it ***appeared*** that a few of the records had duplicates based on the name column.  After further investigation though, we figured out the culprit. 

She had done all the steps correctly, but it was a data integrity issue.  In her data source, the person in charge of entering the data had mistakenly typed a space for a few of the records before entering the name value.  Thus, when Power BI looked for a duplicate in the name column it did its job correctly because “Jamie” is unique compared to “ Jamie”.  That leading white space was the culprit.  Not only did it affect her **Remove Duplicates** step, but it would also have affected a merging of two queries if she had included that as part of her report. 

For this week’s video, I want to show how to use the **Trim** function in the Power Query Editor as a best practice to avoid these unwanted outcomes for any future merges or removing of duplicates.

Don't forget to check out the [Pragmatic Works' on-demand learning platform](https://learning.pragmaticworkstraining.com/) for more insightful content and training sessions on [**Power BI**](https://pragmaticworks.com/power-bi-training), [Power Apps](https://pragmaticworks.com/power-apps), [Power Automate](https://pragmaticworks.com/power-automate), [Copilot Studio](https://pragmaticworks.com/copilot-studio), [Fabric](https://pragmaticworks.com/fabric), [Azure](https://pragmaticworks.com/azure) and other Microsoft applications. Be sure to subscribe to the [Pragmatic Works YouTube channel](https://www.youtube.com/pragmaticworks?sub_confirmation=1) to stay up-to-date on the latest tips and tricks.

It's also easy to get started with your **7-day free trial**. Just click below and you'll be on your way.

[View full post](https://pragmaticworks.com/blog/trim-before-removing-duplicates-power-query)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Matt Peterson"
  },
  "dateModified" : "2025-06-16T20:06:12.328Z",
  "datePublished" : "2021-02-09T14:50:31Z",
  "headline" : "Best Practice To Trim Before Removing Duplicates or Merging In Power Query Editor",
  "image" : {
    "@type" : "ImageObject",
    "height" : 768,
    "url" : "https://blog.pragmaticworks.com/hubfs/Screenshot%20%2845%29.png",
    "width" : 1366
  },
  "mainEntityOfPage" : "https://pragmaticworks.com/blog/trim-before-removing-duplicates-power-query",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60.0,
      "url" : "https://blog.pragmaticworks.com/hubfs/PW%20Logo-2.png",
      "width" : 217.56097
    },
    "name" : "Pragmatic Works Blog"
  }
}
```