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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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