Friday, 31 January 2025

if

 The IF function in Excel is one of the most commonly used logical functions. It allows you to perform conditional tests on values and formulas, returning one value if the condition is TRUE and another if it is FALSE. Below are 10 expanded examples of using the IF function, including data and formulas.


Basic Syntax of IF Function

excel
Copy
=IF(logical_test, value_if_true, value_if_false)

1. Simple IF Statement

Scenario: Check if a student passed an exam (Passing score >= 60).

ABC
NameScoreResult
John75=IF(B2>=60, "Pass", "Fail")
Jane55=IF(B3>=60, "Pass", "Fail")

Result:

  • John: Pass

  • Jane: Fail


2. Nested IF Statement

Scenario: Assign grades based on scores.

ABC
NameScoreGrade
John85=IF(B2>=90, "A", IF(B2>=80, "B", IF(B2>=70, "C", "D")))
Jane72=IF(B3>=90, "A", IF(B3>=80, "B", IF(B3>=70, "C", "D")))

Result:

  • John: B

  • Jane: C


3. IF with AND

Scenario: Check if a student passed both subjects (Math >= 60 and Science >= 60).

ABCD
NameMathScienceResult
John7580=IF(AND(B2>=60, C2>=60), "Pass", "Fail")
Jane5565=IF(AND(B3>=60, C3>=60), "Pass", "Fail")

Result:

  • John: Pass

  • Jane: Fail


4. IF with OR

Scenario: Check if a student passed at least one subject (Math >= 60 or Science >= 60).

ABCD
NameMathScienceResult
John7550=IF(OR(B2>=60, C2>=60), "Pass", "Fail")
Jane5545=IF(OR(B3>=60, C3>=60), "Pass", "Fail")

Result:

  • John: Pass

  • Jane: Fail


5. IF with SUM

Scenario: Check if the total sales exceed a target.

ABCD
MonthSalesTargetResult
Jan50006000=IF(SUM(B2)>=C2, "Target Met", "Target Not Met")
Feb70006000=IF(SUM(B3)>=C3, "Target Met", "Target Not Met")

Result:

  • Jan: Target Not Met

  • Feb: Target Met


6. IF with AVERAGE

Scenario: Check if the average score of a student is above 70.

ABCD
NameMathScienceResult
John8575=IF(AVERAGE(B2:C2 )>=70, "Above Average", "Below Average")
Jane6065=IF(AVERAGE(B3:C3 )>=70, "Above Average", "Below Average")

Result:

  • John: Above Average

  • Jane: Below Average


7. IF with COUNT

Scenario: Check if more than 5 students passed the exam.

AB
NameResult
JohnPass
JaneFail
AlicePass
BobPass
CarolPass
DavePass
EvePass

Formula:

excel
Copy
=IF(COUNTIF(B2:B8, "Pass")>5, "More than 5 passed", "5 or fewer passed")

Result: More than 5 passed


8. IF with DATE

Scenario: Check if a project deadline has passed.

ABC
ProjectDeadlineStatus
Project A2023-10-15=IF(B2<TODAY(), "Overdue", "On Track")
Project B2023-11-01=IF(B3<TODAY(), "Overdue", "On Track")

Result (as of today's date):

  • Project A: Overdue

  • Project B: On Track


9. IF with TEXT

Scenario: Check if a cell contains specific text.

AB
NameResult
JohnPass
JaneFail

Formula:

excel
Copy
=IF(B2="Pass", "Congratulations!", "Try Again")

Result:

  • John: Congratulations!

  • Jane: Try Again


10. IF with VLOOKUP

Scenario: Check if a product is in stock using a lookup table.

ABC
ProductStockStatus
Apple10=IF(VLOOKUP(A2, StockTable, 2, FALSE)>0, "In Stock", "Out of Stock")
Banana0=IF(VLOOKUP(A3, StockTable, 2, FALSE)>0, "In Stock", "Out of Stock")

StockTable:

ProductStock
Apple10
Banana0

Result:

  • Apple: In Stock

  • Banana: Out of Stock


These examples demonstrate the versatility of the IF function in Excel. You can combine it with other functions like ANDORSUMAVERAGECOUNTDATETEXT, and VLOOKUP to create powerful conditional logic for your data analysis.

No comments:

Post a Comment