Excel IF function: results by condition, nested IF and IF with AND
Testing conditions with IF in Excel: pass/fail, bonuses, stock levels; nested IF for a grading scale, IF+AND, and the quotes and blank-cell traps — with examples.
IF is the function that teaches Excel to “make decisions”. It tests a condition: if the condition is met it returns one value, otherwise another.
You see it everywhere: a score of 60 or more is “Pass”, otherwise “Fail”; sales above target earn a bonus; stock running low means “Reorder”. You write one formula, fill it down thousands of rows, and Excel decides for every row on its own.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Result | |
| 2 | Aziz | 92 | Pass | |
| 3 | Dilnoza | 78 | Pass | |
| 4 | Javohir | 55 | Fail | |
| 5 | Malika | 43 | Fail | |
| 6 | Sardor | 67 | Pass | |
| 7 |
=ЕСЛИ(B2>=60;"Pass";"Fail") in C2: a score of 60 or more gives “Pass”, anything else “Fail”Syntax
=ЕСЛИ(logical_test; [value_if_true]; [value_if_false])
- logical_test — a condition that returns TRUE or FALSE:
B2>=60,C2="Tashkent",D2<>0. - value_if_true — what to return when the condition is met: text, a number, a cell or another formula.
- value_if_false — what to return when it is not met. If you leave it out, Excel returns FALSE.
Comparison operators: = equal, <> not equal, > greater, < less, >= greater or equal, <= less or equal.
Golden rule: text in a formula always goes in quotes — "Pass". Numbers and cell addresses go without quotes — 60, B2.
Example
Formula:
=IF(B1>=B2,"Target met","Not met")→ result: Target met
Entering IF step by step
1
Select the result cell (C2) and choose Формулы → Логические → IF.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Result | |
| 2 | Aziz | 92 | ||
| 3 | Dilnoza | 78 | ||
| 4 | Javohir | 55 | ||
| 5 |
2
In the Function Arguments window fill in three boxes: Logical_test — B2>=60, Value_if_true — Pass, Value_if_false — Fail. In this window Excel adds the quotes for you; when typing in a cell you add them yourself.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Result | |
| 2 | Aziz | 92 | Pass | |
| 3 | Dilnoza | 78 | ||
| 4 | Javohir | 55 | ||
| 5 |
3
Click OK, then double-click the fill handle of C2 to copy the formula down. Each row is tested against its own score.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Result | |
| 2 | Aziz | 92 | Pass | |
| 3 | Dilnoza | 78 | Pass | |
| 4 | Javohir | 55 | Fail3 | |
| 5 |
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Product | In stock | Status | Minimum | ||
| 2 | Rice | 120 | Enough | 501 | ||
| 3 | Oil | 35 | Reorder | |||
| 4 | Sugar | 50 | Enough | |||
| 5 | Flour | 18 | Reorder | |||
| 6 |
$E$2: change the minimum and every status recalculates. Sugar at 50 is “Enough”, because 50<50 is falseNested IF: more than two outcomes
IF only splits into two paths. For three or more outcomes, put another IF in place of value_if_false. For example, a grade on a 100-point scale:
=ЕСЛИ(B2>=86;"Excellent";ЕСЛИ(B2>=71;"Good";ЕСЛИ(B2>=55;"Fair";"Poor")))
Excel checks the conditions left to right and stops at the first one that is true. That is why the order “largest to smallest” matters: first >=86, then >=71, then >=55. You need as many closing brackets as IFs — three ) at the end here.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Student | Score | Grade | |
| 2 | Aziz | 92 | Excellent | |
| 3 | Dilnoza | 78 | Good | |
| 4 | Javohir | 55 | Fair | |
| 5 | Malika | 43 | Poor | |
| 6 | Sardor | 86 | Excellent | |
| 7 |
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Student | Score | Plain IF | Correct | |
| 2 | Aziz | 92 | Pass | Pass | |
| 3 | Javohir | Fail1 | Absent | ||
| 4 | Malika | 43 | Fail | Fail | |
| 5 |
ISBLANK(B3) or B3=""Pro level: IF + AND/OR, IFS and calculations
- Several conditions together:
=ЕСЛИ(И(B2>=10000000;C2=0);B2*10%;0)— a bonus if sales exceed 10 million and there were no late arrivals. For “or” useOR:=ЕСЛИ(ИЛИ(D2="VIP";B2>=5000000);"Discount";""). - IF can calculate: return a formula instead of text —
B2*10%,SUM(C2:E2),B2-C2. - Leave it blank: use
""as value_if_false and the cell looks empty. - IFS (Excel 2019/365): a flat list instead of nesting —
=ЕСЛИМН(B2>=86;"Excellent";B2>=71;"Good";B2>=55;"Fair";ИСТИНА;"Poor"). The finalTRUEmeans “everything else”. - Multi-tier scales (tax, commission, discounts): don’t write more than 4–5 IFs — put the thresholds in a separate table and use
XLOOKUPor an approximate-matchVLOOKUP.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | Sales | Late days | Bonus | |
| 2 | Aziz | 12 500 000 | 0 | 1 250 000 | |
| 3 | Dilnoza | 11 000 000 | 2 | 0 | |
| 4 | Javohir | 15 000 000 | 0 | 1 500 000 | |
| 5 | Malika | 8 000 000 | 0 | 0 | |
| 6 |
B2*10%Try it in the simulator
Type =ЕСЛИ(B2>=60;"Pass";"Fail") in C2 and fill it down to C6. Then write a nested IF in D2: =ЕСЛИ(B2>=86;"Excellent";ЕСЛИ(B2>=71;"Good";ЕСЛИ(B2>=55;"Fair";"Poor"))) and fill it down too. Malika should get “Fail” and “Poor”.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Student | Score | Result | Grade | ||||||||||||||||||||
| 2 | Aziz | 92 | ||||||||||||||||||||||
| 3 | Dilnoza | 78 | ||||||||||||||||||||||
| 4 | Javohir | 55 | ||||||||||||||||||||||
| 5 | Malika | 43 | ||||||||||||||||||||||
| 6 | Sardor | 67 | ||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.