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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors