IF and Logical Tests
Use comparison operators, the IF function, AND, OR and IFS to label, score and calculate values automatically based on conditions.
Welcome back!
Step 1 of 14Learn
Questions with TRUE or FALSE answers
A teacher has 300 test scores and needs "Pass" or "Fail" next to each one. A manager needs to flag every invoice older than 30 days. A store needs to give free shipping to orders over $50. All three are the same kind of task: ask a yes-or-no question about each row, then act on the answer.
The question part is a logical test, built with comparison operators:
| Operator | Meaning | Example (B2 = 75) | Result |
|---|---|---|---|
| = | equal to | =B2=70 | FALSE |
| > | greater than | =B2>70 | TRUE |
| < | less than | =B2<70 | FALSE |
| >= | greater than or equal | =B2>=75 | TRUE |
| <= | less than or equal | =B2<=60 | FALSE |
| <> | not equal to | =B2<>70 | TRUE |
Type =B2>=70 into a cell and Excel answers TRUE or FALSE. That alone is useful for spotting rows, but it gets far more useful when the answer chooses what to display or calculate.
Watch the boundaries. "Orders over $50" means >50, so a $50.00 order does not qualify; "$50 or more" means >=50. Many business disputes come down to one missing equals sign. Text comparisons work too: =C2="Closed" is TRUE when C2 holds Closed. Text must be in double quotes, and comparisons ignore upper and lower case.
Step 2 of 14Flashcards
Comparison operators
Tap a card to flip it.
Step 3 of 14Learn
The IF function
IF turns a test into a decision:
=IF(logical_test, value_if_true, value_if_false)
=IF(B2>=70, "Pass", "Fail")shows Pass for 70 or more, Fail otherwise.=IF(D2>50, 0, 7.99)charges $7.99 shipping unless the order is over $50.=IF(C2>10000, C2*5%, 0)pays a 5% bonus on sales over $10,000, else nothing.=IF(E2="", "Missing", E2*2)avoids calculating on an empty cell; "" means an empty text string.
The results can be text (in quotes), numbers, cell references or whole formulas. Text results need quotes; numbers and formulas do not. If you write =IF(B2>=70, Pass, Fail) without quotes, Excel looks for something named Pass and shows #NAME?.
Keep thresholds in cells when they might change: =IF(B2>=$H$1, "Pass", "Fail") with the pass mark in H1 lets you move the pass mark from 70 to 65 and re-grade 300 students instantly. Note the $ signs, because the formula will be copied down.
A good habit is to check a few rows by hand, especially values right at the boundary. Test a score of exactly 70, one just below, and one blank cell, and confirm each result matches the rule you intended.
Step 4 of 14Diagram
How =IF(B2>=70, "Pass", "Fail") decides
Tap a shape with to see more.
- Is B2 >= 70?
- TRUE: show "Pass"
The value_if_true argument.
- FALSE: show "Fail"
The value_if_false argument.
Step 5 of 14Practice · Work it out
B2 holds 480. What does =IF(B2>500, B2*0.1, 25) return?
Step 6 of 14Learn
Combining conditions: AND, OR, NOT
Real rules often have more than one condition. Three functions combine tests:
- AND(test1, test2, …) is TRUE only if every test is TRUE.
- OR(test1, test2, …) is TRUE if at least one test is TRUE.
- NOT(test) flips TRUE to FALSE and back.
Put them inside IF as the logical test:
- Bonus only for employees with sales of at least $50,000 and a customer rating of 4.5 or higher:
=IF(AND(B2>=50000, C2>=4.5), "Bonus", "No bonus"). - Free shipping if the order is over $50 or the customer is a member:
=IF(OR(D2>50, E2="Member"), 0, 7.99). - Flag anything that is not yet closed:
=IF(NOT(F2="Closed"), "Follow up", ""), which is the same as using <>.
Translating a sentence into AND or OR is where most mistakes happen. "Customers in Texas or California" is OR, because no customer can be in both. Writing AND(G2="TX", G2="CA") will never be TRUE. On the other hand, "between 18 and 65" needs AND(H2>=18, H2<=65); with OR, every age passes, because every number is either at least 18 or at most 65.
Step 7 of 14Practice · Diagram
Who gets the bonus?
With =IF(AND(sales>=50000, rating>=4.5), ...), which region earns the bonus?
Tap the shape that answers the question, then press Check.
- Sales ≥ $50k
- Rating ≥ 4.5
- Sales ≥ $50k only
OR: bonus. AND: no bonus.
- Big sales, lower rating
- Rating ≥ 4.5 only
OR: bonus. AND: no bonus.
- Great rating, smaller sales
- Rating ≥ 4.5 + Sales ≥ $50k (overlap)
Bonus under AND and under OR.
- Both targets met
Step 8 of 14Practice · True or false
=OR(B2<10, B2>100) returns TRUE when B2 is 55.
Step 9 of 14Learn
More than two outcomes: nested IF and IFS
What if a score needs a letter grade: A for 90+, B for 80+, C for 70+, F below 70? One IF has only two outcomes, so you can place another IF in the value_if_false slot. This is called nesting:
=IF(B2>=90, "A", IF(B2>=80, "B", IF(B2>=70, "C", "F")))
Excel checks the tests in order and stops at the first TRUE one. A score of 85 fails the first test, passes the second, and gets "B". The order matters: start with the strictest test. If you started with B2>=70, a 95 would get "C", because 95 >= 70 is TRUE and Excel would never reach the other tests.
In Microsoft 365 and Excel 2019 or later, IFS is easier to read:
=IFS(B2>=90, "A", B2>=80, "B", B2>=70, "C", TRUE, "F")
IFS takes test/result pairs. The final TRUE acts as "everything else"; without it, a score below 70 would produce #N/A.
Once you have more than four or five tiers, a small lookup table with approximate-match XLOOKUP or VLOOKUP (next lessons) is easier to maintain than a long formula. Changing a grade boundary then means editing one cell instead of rewriting a nested formula.
Step 10 of 14Practice · Diagram
Grade boundaries for the nested IF
Which score gets a B?
Tap the shape that answers the question, then press Check.
- Score 65
65
- Score 72
72
- Score 85
85
- Score 93
93
Step 11 of 14Practice · Choose one
A colleague wrote =IF(B2>=60, "D", IF(B2>=70, "C", IF(B2>=80, "B", "A"))). What does it return for a score of 85?
Step 12 of 14Note
Step 13 of 14Practice · What would you do?
What would you do?
A sales team's rule: reps earn a $500 bonus if they close at least 20 deals and keep refunds under 5%; otherwise 0. Deals are in C2 and refund rate in D2 (stored as a decimal, so 5% is 0.05). Which formula implements the rule?
Step 14 of 14Practice · Fill in the blanks
Fill in the blanks
To show "Over budget" when the actual cost in C2 is greater than the budget in B2, and "OK" otherwise, write =IF(, "Over budget", "OK").
Lesson complete!