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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Syndicate_Admin
Administrator
Administrator

Power Query delete row if value found in another column

Hi, I’m very new to power query but just can’t find a suitable solution. I need to remove a row if the same value exists in another column. I know I need a conditional statement then a filter but just don’t know how to put it all together. So if ID B exists in ID A remove the corresponding ID A row.

ID A.    ID B

1      
2

3

4         1

5         3


so here the first and third row in ID A would be removed. I would want to keep the row where the value is duplicated in ID B

 

thanks for any advice.

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUVKK1YlWMoIxjGEMEyDDEMwyBbKMlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID A" = _t, #"ID B" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID A", Int64.Type}, {"ID B", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID A"}, #"Changed Type", {"ID B"}, "Changed Type", JoinKind.LeftAnti),
    #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"Changed Type"})
in
    #"Removed Columns"

 

Input:

sevenhills_0-1702420174792.png

 

 

Output:

sevenhills_1-1702420195456.png

 

Explanation:

You are joining back to the same table you are in and do the left anti.

 

sevenhills_2-1702420263228.png

 

Hope this helps!

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

=Table.SelectRows(YourTable,each not List.Contains(YourTable[ID B],[ID A]))

Thanks - I'm still getting my head around all the functions available so good to know some new ones.

sevenhills
Super User
Super User

Try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUVKK1YlWMoIxjGEMEyDDEMwyBbKMlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ID A" = _t, #"ID B" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID A", Int64.Type}, {"ID B", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID A"}, #"Changed Type", {"ID B"}, "Changed Type", JoinKind.LeftAnti),
    #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"Changed Type"})
in
    #"Removed Columns"

 

Input:

sevenhills_0-1702420174792.png

 

 

Output:

sevenhills_1-1702420195456.png

 

Explanation:

You are joining back to the same table you are in and do the left anti.

 

sevenhills_2-1702420263228.png

 

Hope this helps!

Thanks, I appreciate you explaining the logic behind it. Really useful.  

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.