What does the IF function do?
Before learning how to use the IF function in Excel let’s have a look at what it does. The IF function in Excel is used to perform logical tests and return different values based on whether the condition is TRUE or FALSE.
Why is the IF function useful?
The IF function is particularly useful for performing checks and automating data processing within datasets. Since the IF function can be nested, it allows for more complex conditions and returns the corresponding results.
Syntax
See below the correct syntax required to use the IF function in Excel:
=IF(logical_test, value_if_true, value_if_false)
logical_test: A condition that evaluates to TRUE or FALSE.value_if_true: The result if the condition is TRUE.value_if_false: The result if the condition is FALSE.
How to use the IF function in Excel
Examples of IF function usage
The IF function serves multiple purposes and can be applied in various ways. Below are different use cases, each with clear explanations and practical examples.
1. Basic IF Example: Pass or Fail
Let’s say we have student scores and want to determine whether they Passed (≥50) or Failed (<50).
| A | B | C | |
|---|---|---|---|
| 1 | Student | Score | Result |
| 2 | Alice | 85 | ✅ Pass |
| 3 | Bob | 40 | ❌ Fail |
| 4 | Charlie | 72 | ✅ Pass |
| 5 | David | 48 | ❌ Fail |
| 6 | Emma | 90 | ✅ Pass |
📌 Formula in Column C
=IF(B2>=50, "Pass", "Fail")
🚨 Result: If the score is 50 or more, it returns “Pass”; otherwise, it returns “Fail”.
2. IF with Multiple Conditions (Nested IF)
If we want to assign grades based on the score. Multiple verifications are required:
| A | B | C | |
|---|---|---|---|
| 1 | Student | Score | Grade |
| 2 | Alice | 85 | A |
| 3 | Bob | 40 | F |
| 4 | Charlie | 72 | B |
| 5 | David | 48 | F |
| 6 | Emma | 90 | A |
📌 Formula
=IF(B2>=80, "A", IF(B2>=60, "B", IF(B2>=50, "C", "F")))
🚨 Breakdown:
- If the score is 80 or more, return
"A". - If the score is between 60 and 79, return
"B". - If the score is between 50 and 59, return
"C". - Otherwise, return
"F".
3. IF with AND & OR (Multiple Conditions)
Example: Bonus Eligibility
To give a bonus, an employee must work for at least 5 years and have a performance score of 80 or more.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Employee | Years of Service | Performance Score | Bonus Eligibility |
| 2 | Alice | 6 | 85 | ✅ Yes |
| 3 | Bob | 4 | 90 | ❌ No |
| 4 | Charlie | 7 | 78 | ❌ No |
| 5 | David | 5 | 82 | ✅ Yes |
📌 Formula Using AND
=IF(AND(B2>=5, C2>=80), "Yes", "No")
🚨 Explanation:
- AND(B2>=5, C2>=80) ensures that both conditions must be met.
- If both are TRUE, return
"Yes", otherwise return"No".
Example: Discount Eligibility
A customer gets a discount if they spend $500 or more OR have been a customer for at least 3 years.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer | Years as Customer | Amount Spent | Discount? |
| 2 | Alice | 2 | $600 | ✅ Yes |
| 3 | Bob | 4 | $450 | ✅ Yes |
| 4 | Charlie | 1 | $300 | ❌ No |
| 5 | David | 3 | $500 | ✅ Yes |
📌 Formula Using OR
=IF(OR(B2>=3, C2>=500), "Yes", "No")
🚨 Explanation:
- OR(B2>=3, C2>=500) means that either condition can be true for a discount.
- If at least one is met, return
"Yes"; otherwise, return"No".
4. IF with Dates
Example: Check if a Deadline Has Passed
| A | B | C | |
|---|---|---|---|
| 1 | Task | Deadline | Status |
| 2 | Report A | 01/15/2024 | 🚩 Overdue |
| 3 | Report B | 02/25/2024 | 🕒 Upcoming |
| 4 | Report C | 01/30/2024 | 🚩 Overdue |
📌 Formula
=IF(B2<TODAY(), "Overdue", "Upcoming")
🚨 Explanation:
- TODAY() gets the current date.
- If the deadline is before today, return
"Overdue", otherwise"Upcoming".
5. IF with Blank Cells
Example: Check if a Cell is Empty
If B2 is blank, display "Missing Data", otherwise display "Complete".
| A | B | C | |
|---|---|---|---|
| 1 | Customer | Years as Customer | Result |
| 2 | Alice | 2 | ✅ Complete |
| 3 | Bob | 4 | ✅ Complete |
| 4 | Charlie | ❌Missing Data | |
| 5 | David | 3 | ✅ Complete |
📌 Formula
=IF(B2="", "Missing Data", "Complete")
Summary
As seen through the previous examples the IF function is versatile and has many use cases. It can be adapted depending on the situation to provide adequate results. Below are all the previous examples summarized in a table:
| Use Case | Formula Example |
|---|---|
| Basic IF (Pass/Fail) | =IF(B2>=50, "Pass", "Fail") |
| Nested IF (Grades) | =IF(B2>=80, "A", IF(B2>=60, "B", IF(B2>=50, "C", "F"))) |
| IF with AND (Bonus Eligibility) | =IF(AND(B2>=5, C2>=80), "Yes", "No") |
| IF with OR (Discount Eligibility) | =IF(OR(B2>=3, C2>=500), "Yes", "No") |
| IF with Dates (Deadline Check) | =IF(B2<TODAY(), "Overdue", "Upcoming") |
| IF for Blank Cells | =IF(B2="", "Missing Data", "Complete") |
See also our products and tools
Gumroad Shop: