Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
cah2035
Frequent Visitor

Removing duplicates but maintaining one of the columns that is different

Hello. I am trying to remove duplicates from my table using only a certain amount of columns, and I know that one column contains different information between two duplicates. I want to be able to have a single row of the duplicated information and have each non-duplicated data as either two columns or, even better, concatenate them into one cell. 

 

Below is an easy example. Amanda actually has TWO favorite ice cream flavors, and because of that, appears on two different rows. I want to remove duplicate people based on Name, Age, and Date because I only ever want one entry for those, but I want to keep the information about Amanda having two favorite flavors of ice cream. 

 

Backgroup: I am trying to curate a mess of data from a bunch of different tables that we had been keeping for years for the purpose of putting it in an actually relational database.

 

NameAgeHair ColorFav Ice Cream
Amanda25

Brown

Chocolate
Amanda25BrownStrawberry
John31RedChocolate
Peter35GrayVanilla

 

NameAgeFav ColorFav Ice Cream 1Fav Ice Cream 2
Amanda25BrownChocolateStrawberry
John31RedChocolatenull
Peter35GrayVanillanull
1 ACCEPTED SOLUTION
edhans
Super User
Super User

Hi @cah2035 , 

Give this a shot. It transforms this:

edhans_0-1594684810982.png

into this:

edhans_1-1594684849217.png

If you still want the flavors in 2+ columns, you can just split those columns by the comma delimiter.

Here is the code that does it. It basically is a grouping by the name, age, and hair color, then it combines the flavors into a list separated by commas. Put this in a blank query following the directions at the bottom.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxNzEtJVNJRMjIFEk5F+eV5QNo5Iz85PyexJFUpVgeXmuCSosTypNSiokqwIq/8DJCosSGQCEpNwTAkILUktQikAGSGe1FiJZAKS8zLzMlJVIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Age = _t, #"Hair Color" = _t, #"Fav Ice Cream" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Hair Color", type text}, {"Fav Ice Cream", type text}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", 
            {"Name", "Age", "Hair Color"}, 
            {
                {"Flavor", 
                each 
                Text.Combine(
                    List.Transform(
                        [Fav Ice Cream],
                         Text.From
                         ),
                    ", "
                    ), 
                    type text
                }
            }
        )
in
    #"Grouped Rows"

 

1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

6 REPLIES 6
edhans
Super User
Super User

Hi @cah2035 , 

Give this a shot. It transforms this:

edhans_0-1594684810982.png

into this:

edhans_1-1594684849217.png

If you still want the flavors in 2+ columns, you can just split those columns by the comma delimiter.

Here is the code that does it. It basically is a grouping by the name, age, and hair color, then it combines the flavors into a list separated by commas. Put this in a blank query following the directions at the bottom.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsxNzEtJVNJRMjIFEk5F+eV5QNo5Iz85PyexJFUpVgeXmuCSosTypNSiokqwIq/8DJCosSGQCEpNwTAkILUktQikAGSGe1FiJZAKS8zLzMlJVIqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Age = _t, #"Hair Color" = _t, #"Fav Ice Cream" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}, {"Hair Color", type text}, {"Fav Ice Cream", type text}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", 
            {"Name", "Age", "Hair Color"}, 
            {
                {"Flavor", 
                each 
                Text.Combine(
                    List.Transform(
                        [Fav Ice Cream],
                         Text.From
                         ),
                    ", "
                    ), 
                    type text
                }
            }
        )
in
    #"Grouped Rows"

 

1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi @edhans 

 

Thanks, that worked for me. 

 

Also, how did you get that top row where is shows you the count of empties and errors? That would be extremely useful!

Great @cah2035 - Can you mark it as the solution so others can find it and know that it worked?

 

In Power Query, go to the View tab.

Check Column Distribution and Column Quality.

 

Column Profile is also handy, but takes up half of the screen, so I turn it on/off as needed.

edhans_0-1594742255847.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi @edhans 

 

It looks like I don't have those options:

cah2035_0-1594744650908.png

 

@edhans 

 

I figured it out, these options are not available in Power Query for Excel, but I do have Power BI so I see them there. I still don't fully understand when I should use Power BI instead of Power Query in Excel, but I guess this is a good example of why I should switch over. 

Those options do exist in Excel, but you need to have either Excel 2019, or Office 365. They have been available for a few years, but not in Excel 2016 or earlier.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors