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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.