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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ColinWatson
New Member

Remove duplicates in one column based on a given category in another column

Hi All,

 

I have a set of data that looks like the following:

Class NameClass NumberParticipant
Class A1Alex
Class A1Brad
Class A1Alex
Class B2Chase
Class B2Dave
Class B2Alex
Class B2Edward
Class C3Fiona
Class C3Fiona
Class C3Greg
Class C3Henry
Class A4James
Class A4Kelsey
Class A4James
Class A4Dave
Class A4James

 

Each class has a corresponding number/id associated to it, which is unique for each instance of a class.

 

I need a way to remove the repeated participants (those highlighted in red) whom appear more than once for any given Class Number. For instance, James would need to be removed from the list twice because he appears two times alongside the same Class Number; however, Dave does not need to be removed because he appears once as a participant in Class #2 and once as a participants in Class #4.

 

After the removing the duplicates, the table would look like this:

ClassClass NumberParticipant
Class A1Alex
Class A1Brad
Class B2Chase
Class B2Dave
Class B2Alex
Class B2Edward
Class C3Fiona
Class C3Greg
Class C3Henry
Class A4James
Class A4Kelsey
Class A4Dave

 

I'm still new to Power BI and have been struggling with this one for a while. Any help/advice is greatly appreciated.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

In the query editor, just right click on your last step in the steps pane and "Insert Step After", then use one of these to get your result.  Replace Changed Type with the name of your last step.

 

= Table.Distinct(#"Changed Type", {"Class Name", "Class Number", "Participant"}) // if you have more than 3 columns

 

= Table.Distinct(#"Changed Type") // if you have only the 3 columns

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(Source, {{"Class Number", type text}}, "en-IN"),{"Class Name", "Class Number", "Participant"},Combiner.CombineTextByDelimiter(";", QuoteStyle.None),"Merged"),
    Partition = Table.Group(#"Merged Columns", {"Merged"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Index"}, {"Index"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Partition", each [Index] = 1),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Merged", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Merged.1", "Merged.2", "Merged.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", type text}, {"Merged.2", Int64.Type}, {"Merged.3", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Merged.1", "Class Name"}, {"Merged.2", "Class Number"}, {"Merged.3", "Participant"}})
in
    #"Renamed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Microsoft Employee
Microsoft Employee

In the query editor, just right click on your last step in the steps pane and "Insert Step After", then use one of these to get your result.  Replace Changed Type with the name of your last step.

 

= Table.Distinct(#"Changed Type", {"Class Name", "Class Number", "Participant"}) // if you have more than 3 columns

 

= Table.Distinct(#"Changed Type") // if you have only the 3 columns

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you, Pat. Your solution worked absolutely brilliantly. Can't thank you enough!

 

Kind regards

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors