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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Filter table based on value conditions

Hello,

I have the following table loaded in Power Query and i am trying to filter out all the rows in the table based on the "Remaining" column if the value is zero, except if there is a non-zero value for the same "Code" number. Is this possible? Any help is much appreciated!

 

CodeValueDateRemaining
3998147808/06/20210
399832512/04/2022325
399817218/06/2022172
1542198013/06/20220
4253298111/07/20232981
4943178102/09/20221781
3991451008/06/20214510
4060646705/07/20220
4139657005/07/20226570
4145443708/06/20210
4149655405/07/20226554
4150640805/07/20220
4150704908/06/20217049
4151641105/07/20226411
4152441305/07/20224413
4166437205/07/20224372
4166672905/07/20226729
4169677005/07/20220
4169654805/07/20220

 

Expected results:

CodeValueDateRemaining
3998147808/06/20210
399832512/04/2022325
399817218/06/2022172
4253298111/07/20232981
4943178102/09/20221781
3991451008/06/20214510
4139657005/07/20226570
4149655405/07/20226554
4150640805/07/20220
4150704908/06/20217049
4151641105/07/20226411
4152441305/07/20224413
4166437205/07/20224372
4166672905/07/20226729

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

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("dZHZDcQwCER7yXeQOE1cS7T9t7EBH5trvyyGp2HA+75IrduyLqQeDyMTYAGMApfPOgFha30GVCDu0okg50kUoCEFQabRo7rhGZE5RNmi4LpRAwTQgWhoyVSV9BzMYVIBeWg9SjTVCO/bpJY+WKJZtPj0cUD7hSGpAZjjHUitMRq1qvj72Q6gmZg+TQ6tMdaS4PYvSQKO6XWZklpnKE2IHoNC6wxn2jz5hUmtMaVELadvHIz0f+xMca6PWaF1Jhf35/XwApi+bf35Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Value = _t, Date = _t, Remaining = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Value", Int64.Type}, {"Date", type date}, {"Remaining", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Code"}, {{"RemainingCount", each List.Count(List.Select([Remaining], each _ <> 0)), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Code"}, #"Grouped Rows", {"Code"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"RemainingCount"}, {"RemainingCount"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Grouped Rows", each ([RemainingCount] <> 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"RemainingCount"})
in
    #"Removed Columns"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

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("dZHZDcQwCER7yXeQOE1cS7T9t7EBH5trvyyGp2HA+75IrduyLqQeDyMTYAGMApfPOgFha30GVCDu0okg50kUoCEFQabRo7rhGZE5RNmi4LpRAwTQgWhoyVSV9BzMYVIBeWg9SjTVCO/bpJY+WKJZtPj0cUD7hSGpAZjjHUitMRq1qvj72Q6gmZg+TQ6tMdaS4PYvSQKO6XWZklpnKE2IHoNC6wxn2jz5hUmtMaVELadvHIz0f+xMca6PWaF1Jhf35/XwApi+bf35Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Value = _t, Date = _t, Remaining = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Value", Int64.Type}, {"Date", type date}, {"Remaining", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Code"}, {{"RemainingCount", each List.Count(List.Select([Remaining], each _ <> 0)), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Code"}, #"Grouped Rows", {"Code"}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"RemainingCount"}, {"RemainingCount"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Grouped Rows", each ([RemainingCount] <> 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"RemainingCount"})
in
    #"Removed Columns"

 

This, indeed, is the perfect solution and the code is reusable for similar problems. It would be nice if the solution can be replicated using only the GI (conditional columns and the groupby options), for simplicity. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors