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
Anonymous
Not applicable

Remove duplicates based on criteria

Hello, community! 

It's possible to remove duplicates based on this pattern?

Table: 

AB
AC
AD
BA
CA
DA

 

Since I already have the relationship between A and B in the first row, I don't need the fourth row. So I was wondering if there is a logic that I can use to remove B->A, C->A and D->A.

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hello @Anonymous 

I would suggest adding a temporary column(s) that contain the two original values but sorted. Then remove duplicates based on these column(s), and remove the temporary column(s).

 

Here are two examples:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWBsJzhLBcwywnIcgSznOEsFwgrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Combined", each List.Min({[Col1],[Col2]}) & "|" & List.Max({[Col1],[Col2]}), type text),
    #"Removed Duplicates" = Table.Distinct(#"Added Custom", {"Combined"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Combined"})
in
    #"Removed Columns"

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWBsJzhLBcwywnIcgSznOEsFwgrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Min", each List.Min({[Col1],[Col2]}),type text),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Max", each List.Max({[Col1],[Col2]}), type text),
    #"Removed Duplicates" = Table.Distinct(#"Added Custom1", {"Min", "Max"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Min", "Max"})
in
    #"Removed Columns"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hello @Anonymous 

I would suggest adding a temporary column(s) that contain the two original values but sorted. Then remove duplicates based on these column(s), and remove the temporary column(s).

 

Here are two examples:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWBsJzhLBcwywnIcgSznOEsFwgrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Combined", each List.Min({[Col1],[Col2]}) & "|" & List.Max({[Col1],[Col2]}), type text),
    #"Removed Duplicates" = Table.Distinct(#"Added Custom", {"Combined"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Combined"})
in
    #"Removed Columns"

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJSitWBsJzhLBcwywnIcgSznOEsFwgrFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Min", each List.Min({[Col1],[Col2]}),type text),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Max", each List.Max({[Col1],[Col2]}), type text),
    #"Removed Duplicates" = Table.Distinct(#"Added Custom1", {"Min", "Max"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Duplicates",{"Min", "Max"})
in
    #"Removed Columns"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

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