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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rmeng
Helper II
Helper II

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].

 

Untitled.jpg

 

Thanks in advance

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

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 

 

SU18_powerbi_badge

 

View solution in original post

ziying35
Impactful Individual
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

View solution in original post

4 REPLIES 4
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 ?

 

ziying35
Impactful Individual
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
AlB
Super User
Super User

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 

 

SU18_powerbi_badge

 

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 ?

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors