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
bradcuris
New Member

Filter on a group of records

Greetings,

 

I have records grouped by a parent ID. I want to only return the grouped items that do not have a Active = "Current" in the group of records.

 

In the example below, I do not want the top for records (which have a unique parent ID). I want the last three since there is no Active = "Current" (these have another unique parent ID)

 

thanks

 

 

 

bradcuris_0-1657836905620.png

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQCJR0lx4KCovyy1BSlWB2SxZxLi4pS80rAQkZAgK6MKLFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Parent ID" = _t, Active = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent ID", Int64.Type}, {"Active", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Parent ID"}, {{"All", each _, type table [Parent ID=nullable number, Active=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Contains([All][Active],"Current")),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}),
    #"Expanded All" = Table.ExpandTableColumn(#"Removed Columns", "All", {"Active"}, {"Active"})
in
    #"Expanded All"

View solution in original post

3 REPLIES 3
bradcuris
New Member

Thanks,

 

But that only gives 3 rows. I was looking to get back all the rows that match the criteria

Your problem statement says - "I want the last three since there is no Active = "Current" (these have another unique parent ID)"

Hence, you are getting only 3.

In your actual data set, when you apply my method, you will get all unque parent IDs matching the criterion.

You need to replace my Source with your Source and delete changed type. 

Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQCJR0lx4KCovyy1BSlWB2SxZxLi4pS80rAQkZAgK6MKLFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Parent ID" = _t, Active = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Parent ID", Int64.Type}, {"Active", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Parent ID"}, {{"All", each _, type table [Parent ID=nullable number, Active=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Contains([All][Active],"Current")),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}),
    #"Expanded All" = Table.ExpandTableColumn(#"Removed Columns", "All", {"Active"}, {"Active"})
in
    #"Expanded All"

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.

Top Solution Authors
Top Kudoed Authors