Lesson 9
18 min
Combine several conditions for richer calculation rules.
Definition
The AND,OR andNOT functions arelogical operators: they combine or invert conditions to produce a single result, either TRUE or FALSE. Functions are said to benested when they are placed inside one another (for example anANDinside an OR, itself inside an IF) in order to express complex decision rules.
The IF function only tests one condition at a time. To check thatseveral conditions are met simultaneously (or that at least one of them is), Excel offers the ANDand OR functions.
In everyday life, we reason this way all the time: "I'll go out if I have no more workand the weather is nice", or "I'll take the umbrella if it rains or if it's windy". A company's business rules (discounts, bonuses, file approvals) almost always rely on this kind of combination, and AND / OR let you translate them faithfully into a spreadsheet.
AND returns TRUE only if all the given conditions are true. It takes just one false condition for the whole result to be FALSE. It accepts as many conditions as needed, separated by commas.
=AND(B2>=10, C2="Present")
→ TRUE only if the score is ≥10 AND the attendance is "Present"
→ FALSE if either of the two conditions fails
=AND(B2>=10, C2="Present", D2<>"Excluded")
→ with three conditions, all three must be true at the same timeOR returns TRUE as soon as at least one of the given conditions is true. It returns FALSE only if all the conditions are false at the same time. This "or" is inclusive: if both conditions are true, the result is still TRUE.
=OR(B2="VIP", C2>1000)
→ TRUE if the customer is "VIP" OR if their amount exceeds 1000 (or both)
For two conditions A and B, here are all the possible results. This small table lets you mentally check a formula before typing it.
A B AND(A,B) OR(A,B)
TRUE TRUE TRUE TRUE
TRUE FALSE FALSE TRUE
FALSE TRUE FALSE TRUE
FALSE FALSE FALSE FALSEOn their own, AND andOR only return TRUE or FALSE. They are almost always combined withIF to display a more meaningful result. The AND or OR function then takes the place of IF's "condition" argument.
=IF(AND(B2>=10, C2="Present"), "Approved", "Not approved")
=IF(OR(B2="VIP", C2>1000), "Priority customer", "Standard customer")Read the first formula from the inside out: Excel first evaluatesAND(...), which gives TRUE or FALSE, then the IF uses that result to choose between "Approved" and "Not approved". Reading from the inside out is the key to understanding every nested formula.
Let's imagine a sales bonus rule: a salesperson receives a bonus if they made more than 50 sales AND generated revenue above €5,000, ORif they are identified as "Salesperson of the month".
=IF(OR(AND(B2>50, C2>5000), D2="Salesperson of the month"), "Bonus", "No bonus")To build such a formula without getting lost, proceed step by step: first write the condition that groups the sales and the revenue, test it on its own, then add the "Salesperson of the month" status, and finally wrap the whole thing in an IF. Here is how the formula reacts on three different profiles.
Salesperson 1: 60 sales, €7,000, normal status → AND true → "Bonus"
Salesperson 2: 30 sales, €2,000, "Salesperson of the month" → OR true (status) → "Bonus"
Salesperson 3: 60 sales, €3,000, normal status → AND false, status no → "No bonus"
NOT inverts the result of a condition: TRUE becomes FALSE, and vice versa. It is mostly useful for inverting a complex condition, for example the result of anAND or anOR.
=IF(NOT(B2="Done"), "In progress", "Done")
(equivalent to =IF(B2<>"Done", "In progress", "Done"))
=NOT(AND(A2>0, B2>0))
→ TRUE if at least one of the two values is not strictly positiveWhen you nest several functions, every opening parenthesis must have its closing parenthesis, and the position of these parentheses completely changes the meaning of the rule. Compare these two formulas, which do not express the same thing at all.
=OR(AND(A2>0, B2>0), C2>0)
→ true if (A2 and B2 are positive) OR if C2 is positive
=AND(OR(A2>0, B2>0), C2>0)
→ true if (A2 or B2 is positive) AND if C2 is positiveWhen you edit a formula, Excel colors each pair of parentheses: click inside the formula and see which parentheses match each other to check that each group of conditions is properly delimited.
5<B2<10 does not work as it does in mathematics. You must write AND(B2>5, B2<10)."Present", must be enclosed in double quotation marks.Readability
Beyond 2 or 3 nested conditions, a formula quickly becomes hard to read and to fix. In these cases, it is often better to split the calculation into several helper columns (one per condition), before combining everything in a final column.
This method also makes debugging easier: if the final result is wrong, you can look at the helper columns and immediately spot which condition is not behaving as expected. Once the rule is validated, you can always merge the columns into a single formula if needed.
Exercise
Going further
NOT to exclude salespeople whose status is "Suspended".