Forum Discussion
Mic1979
1 year agoPost Partisan
Dynamic Filter Based on Column Name
Hello, I have the following table: and I would like to apply a filter based on the column name, e.g. Distribution. I was trying to write the following code: SelectDistributionColumn =...
- 1 year ago
One method is to add a "Filter Column" which will return True or false depending on your logic. Then filter on that column.
For example, the following code would add a column name'd "Filter"
#"Add Filter Column" = Table.AddColumn(PreviousStep,"Filter", (r)=> //Use List.AllTrue if you want "and" logic //Use List.AnyTrue if you want "or" logic List.AllTrue( List.Transform( Record.FieldValues( Record.SelectFields( r,SelectDistributionColumn)), each _ <> 0 and _ <> null)))Then Filter on that column for true or false.
Mic1979
1 year agoPost Partisan
The are multiple columns, and I want to reference to the selected column by the column name.
Could you suggest the code?
Thanks.
ronrsnfld
1 year agoSuper User
One method is to add a "Filter Column" which will return True or false depending on your logic. Then filter on that column.
For example, the following code would add a column name'd "Filter"
#"Add Filter Column" = Table.AddColumn(PreviousStep,"Filter", (r)=>
//Use List.AllTrue if you want "and" logic
//Use List.AnyTrue if you want "or" logic
List.AllTrue(
List.Transform(
Record.FieldValues(
Record.SelectFields(
r,SelectDistributionColumn)),
each _ <> 0 and _ <> null)))
Then Filter on that column for true or false.
- Mic19791 year agoPost Partisan
Thanks.