Making decisions: IF, AND, OR, IFS and IFERROR
Make Excel decide for you: label rows with IF, combine tests with AND and OR, choose between several outcomes with IFS, and replace error messages with friendly results using IFERROR.
🎯 By the end of this lesson you will be able to:
- Write IF formulas with comparison operators
- Combine conditions with AND and OR, and choose between many results with IFS
- Handle errors with IFERROR
Outline
What you'll learn and why it matters
Reports are full of decisions: over or under budget? Pass or fail? Which commission band? Rather than reading hundreds of rows and typing labels by hand, let a formula decide. IF is one of the most used functions in every office.
IF: one test, two outcomes
=IF(test, value_if_true, value_if_false). The test is a comparison that is TRUE or FALSE:
Worksheet: Budget
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Month | Category | Planned | Actual | Status |
| 2 | Jan | Rent | 15000 | 15000 | OK |
| 3 | Jan | Food | 8000 | 8650 | Over |
| 4 | Jan | Travel | 3000 | 2400 | OK |
| 5 | Feb | Rent | 15000 | 15000 | OK |
| 6 | Feb | Food | 8000 | 7900 | OK |
| 7 | Feb | Travel | 3000 | 3600 | Over |
Formulas (green cells)
- E2 =IF(D2>C2,"Over","OK") → OK
- E3 =IF(D3>C3,"Over","OK") → Over
- E4 =IF(D4>C4,"Over","OK") → OK
- E5 =IF(D5>C5,"Over","OK") → OK
- E6 =IF(D6>C6,"Over","OK") → OK
- E7 =IF(D7>C7,"Over","OK") → Over
| Comparison | Means |
|---|---|
= | Equal to |
<> | Not equal to |
> < | Greater than, less than |
>= <= | Greater or equal, less or equal |
Text in formulas goes in double quotes ("Over"); numbers do not. The result can also be a calculation: =IF(D2>C2, D2-C2, 0) shows how much a budget was exceeded by, or 0.
AND and OR: more than one condition
AND(…) is TRUE only when all its tests are TRUE; OR(…) is TRUE when at least one is. Put them inside IF:
Worksheet: Bonus
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Salesperson | Sales | Customer rating | Bonus? | Review? |
| 2 | Asha | 14250 | 4.6 | Yes | |
| 3 | Ravi | 9870 | 4.8 | No | |
| 4 | Meera | 21430 | 4.2 | No | |
| 5 | Kofi | 7400 | 3.9 | No | Review |
Formulas (green cells)
- D2 =IF(AND(B2>=10000,C2>=4.5),"Yes","No") → Yes
- E2 =IF(OR(B2<8000,C2<4),"Review","") →
- D3 =IF(AND(B3>=10000,C3>=4.5),"Yes","No") → No
- E3 =IF(OR(B3<8000,C3<4),"Review","") →
- D4 =IF(AND(B4>=10000,C4>=4.5),"Yes","No") → No
- E4 =IF(OR(B4<8000,C4<4),"Review","") →
- D5 =IF(AND(B5>=10000,C5>=4.5),"Yes","No") → No
- E5 =IF(OR(B5<8000,C5<4),"Review","") → Review
IFS: several outcomes in order
Instead of nesting IF inside IF, IFS takes pairs of *test, result* and returns the result of the first true test. End with TRUE as a catch-all:
Worksheet: Bands
| Row | A | B | C |
|---|---|---|---|
| 1 | Salesperson | Sales | Band |
| 2 | Asha | 14250 | Silver |
| 3 | Ravi | 9870 | Bronze |
| 4 | Meera | 21430 | Gold |
Formulas (green cells)
- C2 =IFS(B2>=20000,"Gold",B2>=10000,"Silver",TRUE,"Bronze") → Silver
- C3 =IFS(B3>=20000,"Gold",B3>=10000,"Silver",TRUE,"Bronze") → Bronze
- C4 =IFS(B4>=20000,"Gold",B4>=10000,"Silver",TRUE,"Bronze") → Gold
IFERROR: friendly results instead of errors
Some formulas produce errors, such as #DIV/0! when dividing by zero. =IFERROR(formula, value_if_error) shows your own value instead:
Worksheet: Price per unit
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Item | Cost | Units | Per unit | Per unit (safe) |
| 2 | Box of pens | 250 | 10 | 25 | 25 |
| 3 | Sample pack | 0 | 0 | #DIV/0! | No units |
Formulas (green cells)
- D2 =B2/C2 → 25
- E2 =IFERROR(B2/C2,"No units") → 25
- D3 =B3/C3 → #DIV/0!
- E3 =IFERROR(B3/C3,"No units") → No units
| Error | Usually means |
|---|---|
#DIV/0! | Dividing by zero or by an empty cell |
#N/A | A lookup did not find a match (lesson 6) |
#NAME? | A misspelt function name, or text without quotes |
#VALUE! | Maths with text, such as ="ten"*2 |
#REF! | A formula refers to cells that were deleted |
Practice
Guided exercise
Pass or fail
Marks are in B2:B5. In C2, write a formula that shows Pass for marks of 40 or more and Fail otherwise, then copy it down.
- In C2 type
=IF(B2>=40,"Pass","Fail"). - Copy C2 down to C5.
Show the solution
Worksheet: Results
| Row | A | B | C |
|---|---|---|---|
| 1 | Student | Marks | Result |
| 2 | Asha | 78 | Pass |
| 3 | Ravi | 35 | Fail |
| 4 | Meera | 40 | Pass |
| 5 | Kofi | 91 | Pass |
Formulas (green cells)
- C2 =IF(B2>=40,"Pass","Fail") → Pass
- C3 =IF(B3>=40,"Pass","Fail") → Fail
- C4 =IF(B4>=40,"Pass","Fail") → Pass
- C5 =IF(B5>=40,"Pass","Fail") → Pass
How to get there: >=40 includes 40 itself, so Meera passes. Only Ravi, with 35, fails. The text results need double quotes; the number 40 does not.
Your turn
Over budget by how much?
For the budget rows, show how much each category went over budget (Actual minus Planned), or 0 if it did not.
Show the solution
Worksheet: Budget
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Month | Category | Planned | Actual | Over by |
| 2 | Jan | Rent | 15000 | 15000 | 0 |
| 3 | Jan | Food | 8000 | 8650 | 650 |
| 4 | Jan | Travel | 3000 | 2400 | 0 |
| 5 | Feb | Rent | 15000 | 15000 | 0 |
| 6 | Feb | Food | 8000 | 7900 | 0 |
| 7 | Feb | Travel | 3000 | 3600 | 600 |
Formulas (green cells)
- E2 =IF(D2>C2,D2-C2,0) → 0
- E3 =IF(D3>C3,D3-C3,0) → 650
- E4 =IF(D4>C4,D4-C4,0) → 0
- E5 =IF(D5>C5,D5-C5,0) → 0
- E6 =IF(D6>C6,D6-C6,0) → 0
- E7 =IF(D7>C7,D7-C7,0) → 600
How to get there: The true result is a calculation, D − C, and the false result is 0. Food went over by 650 in January and Travel by 600 in February. You could also write =MAX(D2-C2,0).
Common mistakes
Forgetting quotes around text results
You see: #NAME?
Fix: Write "Pass", not Pass.
Putting quotes around numbers
You see: Comparisons fail, because "40" is text
Fix: Write numbers without quotes: B2>=40.
Testing the widest band first in IFS
You see: Everyone lands in the first band
Fix: Order tests from strictest to widest.
Hiding real problems with IFERROR everywhere
You see: Mistakes in formulas go unnoticed
Fix: Use IFERROR only where an error is expected, such as dividing by a count that may be zero.
Recap
- =IF(test, if_true, if_false) labels or calculates based on a comparison.
- AND needs all tests true; OR needs at least one. Use them inside IF.
- IFS returns the result of the first true test; end with TRUE as a catch-all.
- IFERROR replaces expected errors (like #DIV/0!) with a friendly value.
Key terms
- Logical test
- A comparison that is either TRUE or FALSE, such as B2>=40.
- Nested function
- A function used inside another one, such as AND inside IF.
- Error value
- A result such as #DIV/0! or #N/A that shows a formula could not calculate.
Check your understanding
Answer all 4 questions, then check your answers to see an explanation for each one.
1. What does =IF(B2>100,"High","Low") show when B2 is 100?
2. When is AND(B2>5, C2>5) TRUE?
3. What does #DIV/0! mean?
4. In =IFS(B2>=10000,"Silver",B2>=20000,"Gold",TRUE,"Bronze"), what does 25000 get?
Mark this lesson complete
Finished this lesson?
When you have worked through the examples and exercises, mark it complete to save your progress.