Forum Discussion
Order in which filter works
Was wondering how filter works in Power BI from evaluating a context's records.
If you have this:
Filter ( 'table'
, boolean 1
&& boolean 2
&& boolean 3
)Will it by default work like this:
Or like this?
- Anonymous1 year ago
Hi DouweMeer
The logical operator && follows the short-circuit evaluation rule. If multiple conditions are connected by && (e.g., A&&B&&C&&D), once any condition returns FALSE, the subsequent conditions will no longer be evaluated, and FALSE will be returned immediately.You can verify the short-circuit property using the following formula:
Test = IF ( TRUE() && FALSE() && DIVIDE(1, 0), // Without short-circuiting, DIVIDE(1,0) would result in an error (division by zero error). "True", "False" )Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi DouweMeer
The logical operator && follows the short-circuit evaluation rule. If multiple conditions are connected by && (e.g., A&&B&&C&&D), once any condition returns FALSE, the subsequent conditions will no longer be evaluated, and FALSE will be returned immediately.You can verify the short-circuit property using the following formula:
Test = IF ( TRUE() && FALSE() && DIVIDE(1, 0), // Without short-circuiting, DIVIDE(1,0) would result in an error (division by zero error). "True", "False" )Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- DouweMeerImpactful Individual
I like your thought, but did you try to remove the false to test whether it returns in an error?
It doesn't :). Probably due to the divide expression on alternative result.
Which doesn't mean your assumption is false, just your argumentation is incorrect.
Versus
Thanks.
- rajendraongole1Super User
Hi DouweMeer - In Power BI, you can apply the filters n daz as follows
FILTER ( 'table', 'table'[Boolean 1] && 'table'[Boolean 2] && 'table'[Boolean 3] )
This means that only rows where all three Boolean columns are TRUE will be returned.The correct filter result should only return Record 4, since it is the only row where all three Boolean values are TRUE.
So the filtering should work like neither image exactly but should result in a single-row table with only Record 4.Hope this works.
- DouweMeerImpactful Individual
That was not the question. The question is not which record would return.
The question is how the boolean expressions are evaluated in the table. If boolean 1 would return false, would it even try to evaluate boolean 2 and boolean 3? Or would it go to the next record without verifying the second one?