Excel Tutorial menu

Excel IF Function and Logical Tests

The IF function lets Excel make a decision: if something is true, show one result; otherwise show another.

The IF Function

Example

text
=IF(logical_test, value_if_true, value_if_false)
  • logical_test: a question with a yes/no answer, like B2>=50
  • value_if_true: what to show if the answer is yes
  • value_if_false: what to show if the answer is no

Comparison Operators

OperatorMeaningExample
=Equal toA2="Karachi"
<>Not equal toA2<>"Karachi"
>Greater thanB2>50
<Less thanB2<50
>=Greater than or equal toB2>=50
<=Less than or equal toB2<=50

Pass or Fail

Students pass with 50 marks or more. In C2:

Example

text
=IF(B2>=50, "Pass", "Fail")
ABC
1StudentMarksResult
2Ali78Pass
3Bilal42Fail
4Ayesha91Pass

Text in a formula must be inside double quotes, like "Pass". Numbers do not need quotes.

IF with a Calculation

The result can also be a calculation. A shop gives 5% discount on bills of Rs 5000 or more:

Example

text
=IF(B2>=5000, B2*5%, 0)
ABC
1CustomerBillDiscount
2Sana7200360
3Hamza31000

AND and OR

Use AND when all conditions must be true, and OR when at least one must be true.

A scholarship needs marks of 80 or more and attendance of 90% or more:

Example

text
=IF(AND(B2>=80, C2>=90%), "Eligible", "Not eligible")

Free delivery is given if the bill is over Rs 3000 or the customer is a member:

Example

text
=IF(OR(B2>3000, C2="Yes"), "Free", "Rs 200")
ABCD
1CustomerBillMemberDelivery
2Ali3500NoFree
3Ayesha1800YesFree
4Bilal1200NoRs 200

Nested IF

To choose between more than two results, put an IF inside another IF. Grades from marks:

Example

text
=IF(B2>=80, "A", IF(B2>=70, "B", IF(B2>=60, "C", "F")))

Excel checks from left to right and stops at the first true test.

IFS: A Cleaner Way

In Excel 2019, Excel 2021 and Microsoft 365, IFS does the same thing more clearly:

Example

text
=IFS(B2>=80, "A", B2>=70, "B", B2>=60, "C", TRUE, "F")

The last pair TRUE, "F" works as "everything else".

MarksGrade
91A
74B
63C
42F

IFERROR

IFERROR shows something friendly instead of an error:

Example

text
=IFERROR(B2/C2, 0)
=IFERROR(B2/C2, "No data")
BC=IFERROR(B2/C2, "No data")
5001050
5000No data

Use IFERROR carefully. It hides all errors, including real mistakes in your formula.

Exercise

Exercise

Cell B2 contains 45. What does =IF(B2>=50, "Pass", "Fail") show?

Learn Excel with a teacher

Join the CIT (Computer Information Technology) course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp