Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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 = List.Select (Table.ColumnNames (RemovedColumn), each Text.Contains (_, "Distribution")),
FilteredTable = Table.SelectRows (Previous_Step, each Record.Field(_, SelectDistributionColumn) <>0)
but this is not working.
Could you help?
Thanks
Solved! Go to Solution.
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.
SelectDistributionColumn is a List, but needs to be a text string, as indicated by the error message you most likely received.
If there is just a single column, then just use the first element of that list.
If there are multiple columns, then you have to reference each column separately.
The are multiple columns, and I want to reference to the selected column by the column name.
Could you suggest the code?
Thanks.
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.
Thanks.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
8 | |
7 |