Functions AND and OR are 2 logic functions that help you to create sophisticated logical tests.
Presentation of the functions
These functions are very useful with logical tests.
Basically, with a logical test, you compare two items only. But if you want to create a test with more than 1 condition, you must use this function. Examples are at the end of this article.
A condition AND returns TRUE if and only if all tests in parenthesis are true.
=AND(test 1,test 2,test 3, ...)
For instance, you have a list of hotels with different criteria like the number of stars (classification), the price of the menu, ...
You want to select a hotel with
- At least 3 stars (B2>=3)
- The price of the menu is maximum 35 (C2<=35)
- And the hotel has a Fitness room (E2="Yes")
So the formula is
As you can see, the test returns TRUE only if all the function's arguments are TRUE.
A condition OR returns TRUE if one (or more) tests of the function is true.
= OR(test 1,test 2,test 3, ...)
You can create an exclusive OR (only one test is true) with the XOR function. This function is generally useful for electronic projects.
Have a look at this article if you want to learn more about it.
Convert TRUE or FALSE to 0 or 1
Do you know that you can convert the result of a test (TRUE or FALSE) to a numeric value (1 or 0) 😉👍
Few situations solve with AND or OR functions
Let's take this customer file. You want to extract some customers according to some criteria.
Solve these questions
Let's consider these different cases.
- How many clients are married with one child
- How many clients are single or divorced
- How many clients are married with an income above 75,000
- How many clients are male, unmarried, and without children
- How many clients are women with 1 or 2 children?
- How many clients are married or in a relationship, with an income greater than or equal to 50,000, and have at least two children?
- The answer for the question 1 is
- The answer to question 2 is
- The answer to question 3 is
- The answer to question 4 is
- The answer to question 5 is
- The answer to question 6 is
Include a test in an IF function
Once you have created your complex logical test with the functions AND or OR, you can include them in the function IF to customize the result returned.
Bryan Daniel E. Madrio
24/11/2020 @ 10:41
I'm asking for consideration to check the answer key for question 3 because I believe that the correct function for it would be "AND". Please reply to my comment if I'm right or wrong to also correct myself. Thank you!
Frédéric LE GUEN
24/11/2020 @ 11:13
Hi, yes, good catch. It's corrected. Thanks