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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Deleting multiple conditions ion ***POWER QUERY***

Hello, I am trying to delete Rows 

Problem:

Account_number   |      SEE_Number   |            SIO_Status

GA12234                |  SEE-234-567       |          NUll                ----------> This row should be deleted without the other

GA12234                |  SEE-234-567       |          Cancelled

GA 55555                |  SEE-001-009       |          NUll

 

The first account number is duplicate. So I want my query to retain the account_number and its "SIO_Status" if it has any and duplicate the other record BUT at the same time retain the null  values of the other Account_number.

 

Desired Solution: 

Account_number   |      SEE_Number   |            SIO_Status

GA12234                |  SEE-234-567       |          Cancelled

GA 55555                |  SEE-001-009       |          NUll

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

M code for your reference.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcnc0NDIyNlHSUQp2ddUFsnRNzcyBPL9QHx+lWB3cCpwT85JTc3JSU6CqTEEAqsrAwBCILeHGxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Account = _t, SEE_Number = _t, SIO_Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Account", type text}, {"SEE_Number", type text}, {"SIO_Status", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Length([SIO_Status])),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"SEE_Number", "Account"}, {{"Count", each List.Max([Custom]), type number}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom", each if[Count] = 9 then "Cancelled" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Count"})
in
    #"Removed Columns"  

 Capture.PNG

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

M code for your reference.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcnc0NDIyNlHSUQp2ddUFsnRNzcyBPL9QHx+lWB3cCpwT85JTc3JSU6CqTEEAqsrAwBCILeHGxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Account = _t, SEE_Number = _t, SIO_Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Account", type text}, {"SEE_Number", type text}, {"SIO_Status", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Length([SIO_Status])),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"SEE_Number", "Account"}, {{"Count", each List.Max([Custom]), type number}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom", each if[Count] = 9 then "Cancelled" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Count"})
in
    #"Removed Columns"  

 Capture.PNG

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thank you!!! That really helped.

Helpful resources

Announcements
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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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