The IF function tests one condition. Real decisions usually need more than one: a bonus only if sales are high and the person has been there long enough, a review if sales are low or the person is new. You get there by putting AND or OR inside IF, and by nesting one IF inside another when you need more than two outcomes. This tutorial covers all three patterns with one small sales table, and every result below was checked in a recalculated spreadsheet.
=IF(AND(C2>=50000,D2>=2),"Bonus","No bonus") needs both tests to be TRUE. =IF(OR(C2<40000,D2<2),"Review","OK") needs at least one of them to be TRUE.The sample data
All examples use this list of sales reps in cells A1:D11: name, region, annual sales and years with the company.
| Rep | Region | Sales | Years |
|---|---|---|---|
| Ana | North | 62,000 | 3 |
| Ben | South | 48,000 | 5 |
| Chloe | East | 85,000 | 1 |
| Dev | West | 51,000 | 2 |
| Ella | North | 39,000 | 4 |
| Finn | East | 73,000 | 6 |
| Grace | South | 90,000 | 2 |
| Hugo | West | 27,000 | 1 |
| Iris | North | 55,000 | 1 |
| Jay | East | 44,000 | 3 |
The building blocks
=IF(logical_test, value_if_true, value_if_false)
=AND(logical1, [logical2], ...)
=OR(logical1, [logical2], ...)
AND returns TRUE only when every argument is TRUE. OR returns TRUE when at least one argument is TRUE. Both return a single TRUE or FALSE, which is exactly what the first argument of IF expects.
1. IF with AND: every condition must be met
A rep earns a bonus when sales are at least 50,000 and they have at least 2 years with the company. In E2, then fill down to E11:
=IF(AND(C2>=50000,D2>=2),"Bonus","No bonus")
Result: Ana, Dev, Finn and Grace get "Bonus" (4 of 10 reps). Two rows show why both tests matter:
- Chloe has the second-highest sales (85,000) but only 1 year, so AND returns FALSE.
- Dev sits exactly on both limits (51,000 and 2 years). Because the formula uses
>=, he qualifies. With>he would not.
2. IF with OR: any one condition is enough
Flag a rep for review when sales are under 40,000 or they have less than 2 years. In F2:
=IF(OR(C2<40000,D2<2),"Review","OK")
Result: Chloe, Ella, Hugo and Iris get "Review". Ella fails only the sales test, Chloe and Iris fail only the years test, and Hugo fails both. OR does not care how many tests are TRUE, as long as at least one is.
OR is also the usual way to match one of several text values in the same column:
=IF(OR(B2="North",B2="East"),"Yes","No")
3. Combine AND and OR in one test
Pick mentors: reps with at least 3 years who work in the North or East region. The OR goes inside the AND:
=IF(AND(D2>=3,OR(B2="North",B2="East")),"Yes","No")
Result: Ana, Ella, Finn and Jay return "Yes". Ben has 5 years but works in the South, so the OR part is FALSE and the whole AND fails.
Read it from the inside out: first OR decides whether the region fits, then AND checks that result together with the years test.
4. Nested IF: more than two outcomes
IF can only return two values. To sort reps into three tiers, put a second IF in the "value if false" slot:
=IF(C2>=80000,"Gold",IF(C2>=50000,"Silver","Bronze"))
Result: Gold for Chloe and Grace, Silver for Ana, Dev, Finn and Iris, Bronze for Ben, Ella, Hugo and Jay.
Excel stops at the first test that is TRUE, so the order matters. Always test the strictest condition first. If you reverse the order, as in =IF(C2>=50000,"Silver",IF(C2>=80000,"Gold","Bronze")), Grace's 90,000 returns "Silver", because the first test already matched and the Gold test never runs.
A cleaner option: IFS
In Excel 2019, Excel for Microsoft 365 and Google Sheets, IFS lists condition/result pairs without nesting:
=IFS(C2>=80000,"Gold",C2>=50000,"Silver",TRUE,"Bronze")
The final TRUE acts as the "everything else" case. IFS still checks the pairs from left to right, so the same ordering rule applies. In older versions such as Excel 2016, stick with nested IF.
How it works
IF only needs one TRUE or FALSE value to decide what to return. AND and OR take several comparisons and reduce them to that single value. For row 2, AND(C2>=50000,D2>=2) becomes AND(TRUE,TRUE), which is TRUE, so IF returns "Bonus". Text comparisons such as B2="North" are not case-sensitive: in the test sheet, B2="north" matched "North" as well.
You can also flip a condition with NOT. =IF(NOT(B2="West"),"Not West","West") returns "Not West" for Ana. Writing B2<>"West" does the same thing and is often easier to read.
Common mistakes
- Writing the condition like a sentence.
=IF(C2>=50000 AND D2>=2, ...)is not valid. AND is a function, so the tests go inside its parentheses, separated by commas. - Wrong order in nested IFs. Test the highest threshold first, or lower tiers will catch rows that belong higher up.
- Quoting numbers.
C2>="50000"compares a number with text and will not behave like a numeric comparison. Leave numbers unquoted; quote only text such as"North". - Using AND on a whole range.
=AND(C2:C11>=50000)returns one TRUE or FALSE for the entire range (FALSE here), not one result per row. Write the formula for one row and fill it down. - Mixing up AND and OR. If too many rows qualify, you probably need AND; if too few, you probably need OR.
- Hard-coding limits. Put thresholds like 50000 in their own cells and reference them with absolute references (for example
$K$1) so you can change them in one place.
FAQ
How many conditions can AND and OR take?
In current versions of Excel, AND and OR accept up to 255 conditions. In practice, if you need more than a handful, a lookup table is usually easier to maintain.
Does IF with AND / OR work in Google Sheets?
Yes. The formulas in this tutorial use the same syntax in Google Sheets, including the nested IF and the IFS version.
How do I count the rows that meet the condition?
Count the result column with COUNTIF. In this example, =COUNTIF(E2:E11,"Bonus") returns 4. To count directly from the raw data with AND logic, COUNTIFS also works without a helper column.
Summary
Use IF(AND(...)) when every condition must be true, IF(OR(...)) when one is enough, and nest OR inside AND for rules such as "3+ years in North or East". When you need more than two results, nest IF or use IFS, and always test the strictest condition first. For more decision formulas, browse the Logical Functions tutorials or the full Excel collection.
Comments
Post a Comment