Forum Discussion
Filter rows query with more than 1 column condition
I want to filter data as per below table
| Test | Cost 1 | Cost 2 | Test | Cost 1 | Cost 2 | |
| A | 0 | 10 | A | 0 | 10 | |
| B | 0 | 0 | C | 10 | 0 | |
| C | 10 | 0 | E | 20 | 20 | |
| D | 0 | 0 | ||||
| E | 20 | 20 |
Input Output
IF Cost1= 0 & Cost2 = 0 then dont populate the row.
Any help will be appreciated
Same logic we can apply in Query Editor as well
File attached
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIAYkMDpVidaCUnKBfCc4ZIwLguKJKuQJaRAYSIjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Test = _t, #"Cost 1" = _t, #"Cost 2" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}, {"Cost 1", Int64.Type}, {"Cost 2", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.AllTrue({[Cost 1]=0, [Cost 2]=0})), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}) in #"Removed Columns"Bascially add a custom column to check condition
=List.AllTrue({[Cost 1]=0, [Cost 2]=0})Then filter the records
6 Replies
- Stachu
Community Champion
I'm not sure I get the request - you need indication how to filter it in DAX for further calculations, or filter it in PowerQUery to reduce number of rows?
The DAX for this should be folllowingTable Filtered = FILTER('Table','Table'[Cost 1]<>0 || 'Table'[Cost 2] <> 0)- Zubair_Muhammad
Community Champion
Also you can create a column and then use it as a VISUAL Filter
Column = AND ( [Cost 1] = 0, [Cost 2] = 0 )
- amay15Frequent Visitor
I want to apply this at query level then load the data. I dont want to create Column after data load.
Thank for quick reply. Looking forward for solution.
- Zubair_Muhammad
Community Champion
Same logic we can apply in Query Editor as well
File attached
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIAYkMDpVidaCUnKBfCc4ZIwLguKJKuQJaRAYSIjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Test = _t, #"Cost 1" = _t, #"Cost 2" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Test", type text}, {"Cost 1", Int64.Type}, {"Cost 2", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.AllTrue({[Cost 1]=0, [Cost 2]=0})), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = false)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}) in #"Removed Columns"Bascially add a custom column to check condition
=List.AllTrue({[Cost 1]=0, [Cost 2]=0})Then filter the records