Forum Discussion

rmeng's avatar
rmeng
Helper II
6 years ago
Solved

Remove ID´s with two categories

Hello, I need to remove the the ID´s that has the [type] = "Account" or "User" with Power Query or with a Dax function if you prefer. In this example Because [ID]="A" has both "Account" and "User" [type] I will only want the "B" [ID].

 

 

Thanks in advance

  • H rmeng 

    So you want to remove the rows that have both "Account" AND "User", not OR. Try this: 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJMTs4vzStRitWB8EOLU4vAHCdkyVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"type" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"type", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"type", each [type]}}),
        res_ = Table.SelectRows(#"Grouped Rows", each not (List.Contains([type], "Account") and List.Contains([type], "User"))),
        #"Removed Columns" = Table.RemoveColumns(res_,{"type"})
    in
        #"Removed Columns"

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Contact me privately for support with any BI needs, tutoring, etc.

    Cheers 

     

     

  • Hi, rmeng 

    my code as below:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJMTs4vzStRitWB8EOLU4vAHCdkyVgA", BinaryEncoding.Base64), Compression.Deflate)),{"ID","type"}),
        selcRows = Table.SelectRows(Source,(row)=>not List.ContainsAll(Table.SelectRows(Source,each [ID]=row[ID])[type],{"Account","User"}))
    in
        selcRows

4 Replies

  • AlB's avatar
    AlB
    Community Champion

    H rmeng 

    So you want to remove the rows that have both "Account" AND "User", not OR. Try this: 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJMTs4vzStRitWB8EOLU4vAHCdkyVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"type" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"type", type text}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"type", each [type]}}),
        res_ = Table.SelectRows(#"Grouped Rows", each not (List.Contains([type], "Account") and List.Contains([type], "User"))),
        #"Removed Columns" = Table.RemoveColumns(res_,{"type"})
    in
        #"Removed Columns"

    Please mark the question solved when done and consider giving kudos if posts are helpful.

    Contact me privately for support with any BI needs, tutoring, etc.

    Cheers 

     

     

    • debasmitad's avatar
      debasmitad
      Frequent Visitor

      Hi, I have similar scenario . But the type column for my data has multiple data , like over 90 and the values are dynamic too, i.e., they might change over time. How I solve that ?

       

  • ziying35's avatar
    ziying35
    Impactful Individual

    Hi, rmeng 

    my code as below:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJMTs4vzStRitWB8EOLU4vAHCdkyVgA", BinaryEncoding.Base64), Compression.Deflate)),{"ID","type"}),
        selcRows = Table.SelectRows(Source,(row)=>not List.ContainsAll(Table.SelectRows(Source,each [ID]=row[ID])[type],{"Account","User"}))
    in
        selcRows
  • debasmitad's avatar
    debasmitad
    Frequent Visitor

    I have a similar scenario, however I have multiple values for type , like over 50. How do I achieve the same in my case ?