Blog

Formula - Boolean And / Or operators - What is the order of precedence?

When we construct expressions that include the Boolean And and Or operators, which operator takes precedence? Find out in this post.

When building logical expressions with Power Apps, it's useful to understand which operator takes precedence when we mix the And and Or operators.

Demonstration - Filtering records with the And and Or operators

As an example, let's assume that we build an app that's based on a table of properties as shown beneath. The requirement is to search for all properties in London, which contain either 5 or more bedrooms, or 3 or more bathrooms.

Let's now add a gallery control and set the Items property to the formula beneath. Will this formula return the expected results?

Filter(
Property,
City="London" And
Bedrooms >= 5 Or
Bathrooms >= 3
)


The answer to the above question is No! As the screenshot beneath highlights, this formula returns records for properties that are not in London.


The And operator takes precedence over Or

This example highlights how the And operator takes precedence over the Or operator. To return our desired results, it's therefore necessary to parenthesis the Or part of the statement. The correct formula will look like this:

Filter(
Property,
City="London" And
(
Bedrooms >= 5 Or
Bathrooms >= 3
)
)

As the screenshot beneath shows, this formula now returns the expected results.

Conclusion

When constructing boolean expressions, Power Apps performs the And/&& operators before the logical Or/|| operators.
Related posts