Logical functions
Some calculations depend on a condition: if the condition is met one result should appear, otherwise another. For this IF(condition, value_if_true, value_if_false) is used. A condition is written with comparison signs: =, <>, <, >, <=, >=. To combine several conditions, AND(c1, c2, …) gives TRUE when all are true, OR(c1, c2, …) gives TRUE when at least one is true, and NOT(c) reverses a condition. With more than two outcomes another IF is written inside the IF: the conditions are checked starting from the strictest. In newer Excel the IFS function shortens such a chain, but nested IF works in every version. Text results are written in quotation marks.
| Sign | Meaning |
|---|---|
| = | equal |
| <> | not equal |
| < | less |
| > | greater |
| <= | less or equal |
| >= | greater or equal |
A school sports club has a rule: a pupil who attends at least eight sessions gets a badge, otherwise the list says “keep going”. The table checks the rule for each row by itself, so the teacher does not have to read hundreds of rows.
Programmers, game designers and school office staff check “if ... then ..., otherwise ...” rules automatically.
Write one rule of your own, such as “if it rains, take an umbrella, otherwise a cap”, and test it against two different kinds of weather.
| B2 | C2 | AND | OR |
|---|---|---|---|
| 72 | 58 | rad | qabul |
“Line up by condition”: students stand up if they meet the condition on a card (for example, “taller than 165 AND the name starts with A”); the class sees the difference between AND and OR in action.