2.2 IF and the logical family
Checked against Microsoft's Excel for Windows keyboard references, August 2026
What you'll be able to do
Make a cell decide something: pass or fail, on time or late, which fee band. The decision then runs itself every month, instead of being made by a tired person on the last evening.
Before you start
Open the formula drills workbook. Its logic drills are the practice for this lesson.
The work
- Same either way: IF is a question with two answers.
=IF(B2>=40, "Pass", "Fail")gives the condition, then the answer when it is true, then the answer when it is false. Type it and press Enter. Now changeB2and watch the verdict follow the data. That following is the point: the decision now lives in the sheet. - Same either way: join conditions with AND and OR inside the question.
=IF(AND(B2>=40, C2>=40), "Pass", "Fail")passes only when both subjects clear the line. OR passes when either one does, and NOT turns a condition around. Read them aloud — "if both of these, then" — and the brackets stop looking like a wall of punctuation. - Same either way: for three or more bands, one IF inside another works but reads badly. IFS states each rule in order and takes the first one that is true:
=IFS(B2>=75, "Distinction", B2>=60, "First", B2>=40, "Pass", TRUE, "Fail"). The finalTRUEcatches everything else. Order matters, because the rules are tried from the top down. - Same either way: when the decision maps exact values to results, SWITCH says it most clearly. Department codes to names, or grades to points:
=SWITCH(B2, "CSE", "Computer Science", "ECE", "Electronics", "Unknown"). When the list of pairs gets long, stop putting it in a formula at all. Put it in two columns and look it up, which is the next topic's work. - Same either way: audit a decision you do not trust by reading it from the inside out. Select the doubtful part of the formula in the formula bar and press F9. Excel shows what that piece works out to. Press Esc afterwards, so the worked-out value is not saved into the formula.
- Same either way: keep logic readable. A formula a classmate cannot read in one pass is a risk, whoever wrote it. Prefer IFS to IF inside IF, and SWITCH to a chain of equality tests. Prefer a lookup table to either when the rules are really data. Put the thresholds themselves — 40, 60, 75 — in named cells. Then changing a rule means editing a cell, not operating on a formula.
Try it
Work the logic drills: a pass or fail column, a three-band grade with IFS, and one SWITCH. Then take the ugliest formula you produced and rewrite it, so that someone else could read it aloud without practice.
Check yourself
Write the shape of an IF that gives "Late" when C2 is after the due date in D2, else "On time".
=IF(C2>D2, "Late", "On time"). The condition comes first, then the true answer, then the false one.
Why does the order of conditions inside IFS matter?
IFS returns the result of the first true condition. With B2>=40 before B2>=75, a mark of 90 would come out as a bare pass. The strictest rule must come first.
When does SWITCH beat IFS?
When one value is matched against exact cases, such as codes, categories or grades, rather than against ranges. One value and many labels reads most cleanly as SWITCH.
At what point should the logic leave the formula entirely?
When the rules are really a table: many pairs, or pairs that change. Put them in cells and use a lookup, because data belongs in cells rather than inside formulas.
Go deeper
We haven't checked most of these for screen reader use yet.
Back to IF and the logical family: work through the checklist