New: 6 free SQL practice datasets with 300+ questions — try the SQL Compiler →
Excel

Excel IF, AND, OR and IFS Functions Explained

Excel logical functions explained: IF, nested IF, AND, OR, IFS and SWITCH, how to combine AND with OR, and the gotchas, with real results from Excel.

Upskly AI Team September 27, 2026 12 min read
Excel IF, AND, OR and IFS Functions Explained

Logical functions in Excel test a condition and then either return TRUE or FALSE, or choose between results. The main ones are IF, AND, OR, NOT, IFS, SWITCH and the error handlers IFERROR and IFNA. IF is the one you will use most: =IF(condition, value_if_true, value_if_false) gives one answer when the condition is true and another when it is not.

This guide goes from a single comparison to nested IF, to combining AND with OR (where the placement of brackets changes the answer), and to the small details that make a correct-looking formula give a wrong result. Every result was produced by running the formula in Microsoft Excel.

In this guide

The short version

  • =IF(test, if_true, if_false). If you leave out if_false and the test fails, Excel shows FALSE.
  • In a nested IF, Excel stops at the first true condition, so test the most specific one first.
  • AND needs every condition true, OR needs at least one. Put an OR inside an AND with brackets, and check the brackets.
  • IFS replaces long nested IFs in Excel 2019 and 365, but needs a final TRUE for the default.

Comparisons and TRUE or FALSE

Every logical function starts from a comparison, which returns TRUE or FALSE. The operators are =, <> (not equal), >, <, >= and <=. A1 holds 15 and B1 holds the text Pune:

Comparisons on A1 = 15 and B1 = Pune
FormulaExcel showsWhy
=A1>10TRUE
=A1>=15TRUE
=A1<>15FALSE<> means not equal
=B1="pune"TRUEtext comparison ignores upper or lower case
=B1="Pune "FALSEa trailing space makes it a different text
=(A1>10)*11TRUE counts as 1 in arithmetic
=TRUE+TRUE2and FALSE counts as 0

The IF function

IF takes a condition and two results. Text results go in double quotes. In column C every mark of 40 or more passes. Column D leaves out the value for a failed test:

What the sheet shows

ABCD
1StudentMarksResultNo else
2Asha82PassPass
3Ravi75PassPass
4Meera60PassPass
5John45PassPass
6Sam39FailFALSE

What is inside the cells (Show Formulas)

ABCD
1StudentMarksResultNo else
2Asha82=IF(B2>=40,”Pass”,”Fail”)=IF(B2>=40,”Pass”)
3Ravi75=IF(B3>=40,”Pass”,”Fail”)=IF(B3>=40,”Pass”)
4Meera60=IF(B4>=40,”Pass”,”Fail”)=IF(B4>=40,”Pass”)
5John45=IF(B5>=40,”Pass”,”Fail”)=IF(B5>=40,”Pass”)
6Sam39=IF(B6>=40,”Pass”,”Fail”)=IF(B6>=40,”Pass”)

Look at D6: when the test fails and there is no value_if_false, Excel returns the word FALSE, which is rarely what you want in a report. Always give both results, even if the second is an empty text "".

Nested IF: several outcomes

When there are more than two outcomes, put another IF in the value_if_false place. Excel checks the conditions in order and stops at the first one that is true. That is why the order matters. Column C tests the highest band first; column D puts the lowest band first; column E uses > instead of >=:

ABCDE
1StudentMarksRight orderWrong orderUses >
2Asha82ACA
3Ravi75ACB
4Meera60BCC
5John45CCC
6Sam39FailFailFail
The three formulas
ColumnFormula in row 2What is wrong or right
C Right order=IF(B2>=75,"A",IF(B2>=60,"B",IF(B2>=40,"C","Fail")))the strictest condition comes first
D Wrong order=IF(B2>=40,"C",IF(B2>=60,"B",IF(B2>=75,"A","Fail")))82 is at least 40, so the first test wins: everyone who passes gets C
E Uses >=IF(B2>75,"A",IF(B2>60,"B",IF(B2>40,"C","Fail")))exactly 75 is not greater than 75, so Ravi drops a grade

Two rules come out of this. Order the tests from the strictest to the loosest (or the other way round with <), and decide whether a boundary value belongs to the upper or the lower band, then pick >= or > to match.

AND, OR and NOT

AND(cond1, cond2, ...) is TRUE only if all conditions are true. OR(...) is TRUE if at least one is true. NOT(cond) flips TRUE and FALSE. They usually sit inside an IF:

What the sheet shows

ABCDEF
1StudentMathsScienceANDORNOT(AND)
2Asha8271PassPassFALSE
3Ravi3590FailPassTRUE
4Meera6030FailPassTRUE
5John2025FailFailTRUE

What is inside the cells

ABCDEF
1StudentMathsScienceANDORNOT(AND)
2Asha8271=IF(AND(B2>=40,C2>=40),”Pass”,”Fail”)=IF(OR(B2>=40,C2>=40),”Pass”,”Fail”)=NOT(AND(B2>=40,C2>=40))
3Ravi3590=IF(AND(B3>=40,C3>=40),”Pass”,”Fail”)=IF(OR(B3>=40,C3>=40),”Pass”,”Fail”)=NOT(AND(B3>=40,C3>=40))
4Meera6030=IF(AND(B4>=40,C4>=40),”Pass”,”Fail”)=IF(OR(B4>=40,C4>=40),”Pass”,”Fail”)=NOT(AND(B4>=40,C4>=40))
5John2025=IF(AND(B5>=40,C5>=40),”Pass”,”Fail”)=IF(OR(B5>=40,C5>=40),”Pass”,”Fail”)=NOT(AND(B5>=40,C5>=40))

Ravi (35 in Maths, 90 in Science) fails the AND rule but passes the OR rule. John fails both.

AND with an OR inside: where the brackets go

Real rules combine both: “call the lead if the city is Pune and either the order is at least 500 or the person is a member”. Condition A must always hold, and condition B is one of two alternatives, so the OR goes inside the AND:

=IF(AND(B2="Pune", OR(C2>=500, D2="Yes")), "Call", "Skip")

Move the brackets and the rule changes. Column F below is OR(AND(city is Pune, order at least 500), member), which means “Pune with a big order, or any member”. It looks almost the same and gives different answers for John and Zoya, who are members outside Pune:

ABCDEF
1NameCityOrderMemberA: AND(city, OR(..))B: OR(AND(..), member)
2AshaPune700NoCallCall
3RaviPune300YesCallCall
4MeeraMumbai900NoSkipSkip
5JohnMumbai200YesSkipCall
6SamPune100NoSkipSkip
7ZoyaDelhi800YesSkipCall

The rule for the brackets: whatever is inside OR( ) is one alternative choice for a single slot of the AND. Say the rule out loud in words first, then place the brackets to match the words. The same logic appears in other tools: in FILTER it is (city="Pune")*((order>=500)+(member="Yes")), where * means AND and + means OR.

IFS and SWITCH

IFS(test1, result1, test2, result2, ...) checks the tests in order and returns the result of the first true one. It avoids the nested brackets. It exists in Excel 2019 and Microsoft 365, not in Excel 2016 or earlier. If nothing matches, IFS returns #N/A, so end with TRUE as a catch-all:

ABCD
1StudentMarksIFS with TRUE at the endIFS without a default
2Asha82AA
3Ravi75AA
4Meera60BB
5John45CC
6Sam39Fail#N/A

SWITCH(value, match1, result1, match2, result2, ..., default) compares one value with a list of exact matches, which suits codes and labels:

A1 holds 2 and A2 holds 9
FormulaExcel showsWhy
=SWITCH(A1,1,"Mon",2,"Tue",3,"Wed","Other")Tue2 matches the second pair
=SWITCH(A2,1,"Mon",2,"Tue",3,"Wed","Other")Othernothing matches, so the default is used
=SWITCH(A2,1,"Mon",2,"Tue",3,"Wed")#N/Ano default given: #N/A

IFERROR and IFNA

IFERROR(value, if_error) replaces any error with a value you choose. IFNA(value, if_na) replaces only #N/A, the error that lookups give when nothing is found. Prefer IFNA when you expect only that case, because IFERROR also hides real mistakes such as a wrong range:

A1 = 10 and B1 = 0
FormulaExcel showsWhy
=A1/B1#DIV/0!division by zero
=IFERROR(A1/B1,"check the divisor")check the divisorIFERROR catches it
=IFNA(A1/B1,"x")#DIV/0!IFNA lets #DIV/0! through
=IFNA(NA(),"not found")not foundIFNA catches #N/A

What Excel evaluates and what it skips

IF only evaluates the branch it picks, so it can guard against an error in the other branch. AND and OR evaluate every argument, so an error in a later argument spoils the answer even if an earlier one already decided it. A1 holds 0:

Guards with IF and with OR
FormulaExcel showsWhy
=IF(A1=0,"skipped",10/A1)skippedthe division is never evaluated
=IF(TRUE,"ok",1/0)okthe error branch is skipped
=OR(A1=0,10/A1>1)#DIV/0!OR still evaluates 10/A1 and fails
=IF(A1=0,TRUE,10/A1>1)TRUEthe safe version: IF decides first
=AND(FALSE,1/0)#DIV/0!AND does not short-circuit either

Gotchas with comparisons

A1 holds 15, A2 holds the text 100, A3 holds the number 100 and A4 is empty:

Comparisons that surprise people
FormulaExcel showsWhy
=10<=A1<=20FALSEdoes not test a range: (10<=15) is TRUE, and TRUE<=20 is FALSE
=AND(A1>=10,A1<=20)TRUEthe correct way to test a range
=A2=A3FALSEtext 100 and number 100 are different
=A2=VALUE(A2)FALSEso the text does not equal its converted self
="abc">100TRUEtext is always greater than any number
=A4=0TRUEan empty cell equals 0 …
=A4=""TRUE… and equals empty text
=IF(0,"yes","no")nozero counts as FALSE
=IF(5,"yes","no")yesany other number counts as TRUE

When nested IF gets too long

Excel allows up to 64 levels of nesting, but nobody should read that. If the bands are a list, put them in a table and let a lookup pick the band. Here the four bands are written as an array constant inside VLOOKUP with approximate matching (the last argument TRUE), which finds the largest lower limit that does not exceed the mark. In a real workbook you would put the band table in cells and point at it:

What the sheet shows

ABC
1StudentMarksGrade from a table
2Asha82A
3Ravi75A
4Meera60B
5John45C
6Sam39Fail

What is inside the cells (Show Formulas)

ABC
1StudentMarksGrade from a table
2Asha82=VLOOKUP(B2,{0,”Fail”;40,”C”;60,”B”;75,”A”},2,TRUE)
3Ravi75=VLOOKUP(B3,{0,”Fail”;40,”C”;60,”B”;75,”A”},2,TRUE)
4Meera60=VLOOKUP(B4,{0,”Fail”;40,”C”;60,”B”;75,”A”},2,TRUE)
5John45=VLOOKUP(B5,{0,”Fail”;40,”C”;60,”B”;75,”A”},2,TRUE)
6Sam39=VLOOKUP(B6,{0,”Fail”;40,”C”;60,”B”;75,”A”},2,TRUE)

The lookup functions are covered in detail in the lookup guide of this series.

Cheat sheet

Logical functions cheat sheet
GoalFormulaNote
Two outcomes=IF(B2>=40,"Pass","Fail")always give both results
Several outcomes=IF(B2>=75,"A",IF(B2>=60,"B","C"))strictest test first
All conditions=AND(A1>=18, A1<=60)test a range with two comparisons
Any condition=OR(B1="Yes", C1>=500)
A and (B or C)=AND(A1, OR(B1, C1))the OR sits inside the AND
(A and B) or C=OR(AND(A1, B1), C1)a different rule from the one above
Many bands, Excel 2019+=IFS(B2>=75,"A",B2>=40,"C",TRUE,"Fail")TRUE as the default
Match a code=SWITCH(A1,1,"Mon",2,"Tue","Other")exact matches only
Hide an error=IFERROR(A1/B1,"")IFNA if only #N/A is expected

Try it yourself

Work out each answer first, then open the solution.

1. Commission is 10% for sales of 10,000 or more, 5% for 5,000 or more, and 2% otherwise. Write one formula for the first row and check it on 12,000, 5,000 and 4,999.

Show solution

What the sheet shows

ABC
1RepSalesCommission rate
2Asha1200010%
3Ravi50005%
4Meera49992%

What is inside the cells (Show Formulas)

ABC
1RepSalesCommission rate
2Asha12000=IF(B2>=10000,0.1,IF(B2>=5000,0.05,0.02))
3Ravi5000=IF(B3>=10000,0.1,IF(B3>=5000,0.05,0.02))
4Meera4999=IF(B4>=10000,0.1,IF(B4>=5000,0.05,0.02))

Test the highest band first. 5,000 gets 5% because the test is >=, and 4,999 drops to 2%.

2. Write a test that is TRUE only when A1 is between 18 and 60 inclusive, and check it on 18, 60, 61 and 17.

Show solution
Testing 18, 60, 61 and 17 in A1 to A4
FormulaExcel shows
=AND(A1>=18,A1<=60)TRUE
=AND(A2>=18,A2<=60)TRUE
=AND(A3>=18,A3<=60)FALSE
=AND(A4>=18,A4<=60)FALSE

Use AND with two comparisons. The shortcut 18<=A1<=60 does not work in Excel.

3. A1 holds 35. What does =IF(A1>=40,"Pass") return?

Show solution
A1 holds 35
FormulaExcel shows
=IF(A1>=40,"Pass")FALSE

With no value_if_false, IF returns FALSE, not an empty cell.

4. What do =OR(TRUE,1/0) and =IF(TRUE,1,1/0) return?

Show solution
Two formulas with a division by zero
FormulaExcel shows
=OR(TRUE,1/0)#DIV/0!
=IF(TRUE,1,1/0)1

OR evaluates all its arguments, so the division fails. IF only evaluates the branch it chooses.

Frequently asked questions

What is the IF function in Excel?

IF(logical_test, value_if_true, value_if_false) tests a condition and returns one result if it is TRUE and another if it is FALSE.

How do I use IF with AND and OR in Excel?

Put AND(...) or OR(...) as the first argument: =IF(AND(B2>=40, C2>=40), "Pass", "Fail"). To combine them, nest one inside the other, for example AND(A1, OR(B1, C1)).

How many IF statements can you nest in Excel?

Up to 64 levels in modern versions of Excel, but readable formulas rarely go beyond three or four. Use IFS, SWITCH or a lookup table instead.

What is the difference between IF and IFS?

IF handles two outcomes and needs nesting for more. IFS takes pairs of test and result and returns the first true one, without nesting. IFS is available in Excel 2019 and Microsoft 365.

Why does my IF formula return FALSE?

Usually because the test failed and the formula has no value for that case: =IF(A1>=40,"Pass"). Add a third argument.

Why does IF give the wrong grade in a nested formula?

Excel stops at the first condition that is true. If the loosest condition comes first, everyone matches it. Test the strictest condition first.

What is the difference between IFERROR and IFNA?

IFERROR catches every error type. IFNA catches only #N/A, so it does not hide mistakes such as #DIV/0! or #REF!.

Is text comparison in Excel case sensitive?

No. ="pune"="PUNE" is TRUE. Use EXACT(a, b) when you need a case-sensitive comparison.

Test yourself

Timed questions on Logical Functions, with an explanation for every answer.

Take the Quiz
Upskly AI Team
Learning made simple
Scroll to Top