Forum Discussion
Power Query: Apply Filter Expression Only if Condition Met in Another Column
- 1 year ago
The next step is to rearrange the query so that the most frequently encountered condition is tested for first etc.
- 1 year ago
There turned out to be some unexpected instances of duplicatation where both range statements were true. (errors in the data) So the final version that worked was:
= Table.SelectRows(#"Expanded All", each [Column3] = 1 or [Column1] >= [Column4] and [Column1] <= [Column5] or not ([Column1] >= [Column4] and [Column1] <= [Column5]) and [Column2] >= [Column4] and [Column2] <= [Column5] )
lbendlin
Below was my prompt for ChatGPT. Maybe I explained what I want more clearly for AI, because I know how "artificial" it can be. 😄 Will your solution accomplish what I describe below?
I have the following expression to filter rows based on a column:
= Table.SelectRows(#"Expanded All", each ([Column1] >= [Column4] and [Column1] <= [Column5]) or ([Column2] >= [Column4] and [Column2] <= [Column5])
)
But I only want to apply the filter if a condition is met in a column currently not referenced in the expression. I want to keep all rows that do not meet the condition, and I want to apply the above filter only to rows that meet that contion.
This is the condition:
if [Column3] > 1
Is there a way to add this condition to the above expression to achieve my goal?
There is some friction between boolean language and natural language.
When you say "I want A and B from column C" then the boolean equivalent is C= "A" OR C = "B".
Like in algebra there is an order of execution. AND executes before OR. if you don't like that you need to protect the OR with parentheses. You don't need to protect the AND, but extra parentheses (while useless) don't hurt.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523