Core Concept & 3-Part Formula Anatomy
The IF function is the foundation of programmatic logic in Excel. It evaluates a specific condition (the logical test) and returns one result if the test is TRUE, and another result if the test is FALSE.
e.g. Sales >= Target
"Target Met" or Sales * 0.10
"Below Target" or 0
Logical Comparison Operators in Excel
Excel uses 6 standard comparison operators to evaluate values in a logical test:
| Operator | Meaning | Example Formula | Evaluates To |
|---|---|---|---|
= | Equal to | =IF(A2 = "Delhi", "Local", "Outstation") | TRUE if cell A2 is "Delhi" |
> | Strictly greater than | =IF(B2 > 100, "High", "Low") | TRUE if B2 is 101+ |
>= | Greater than or equal to | =IF(B2 >= 50, "Pass", "Fail") | TRUE if B2 is 50, 51, 52... |
< | Strictly less than | =IF(C2 < 10, "Reorder", "OK") | TRUE if inventory is 9 or less |
<= | Less than or equal to | =IF(D2 <= 0, "Out of Stock", "Available") | TRUE if D2 is 0 or negative |
<> | Not equal to | =IF(E2 <> 0, "Active", "Inactive") | TRUE if E2 is anything other than 0 |
Text vs. Numeric Return Values
=IF(B2>=C2, "Target Met", "Below Target")
Always wrap text strings in double quotes. Omitting quotes causes a #NAME? error.
=IF(B2>=50000, B2*0.10, 0)
Never put quotes around numbers (e.g. "0"), otherwise Excel treats them as strings and breaks downstream math!
Syntax Errors vs. Logic Errors
- Syntax Error (Crash): Missing parentheses, unclosed quotes (e.g.
=IF(B2>=C2, "Met", "Missed"). Excel will refuse to accept the formula. - Logic Error (Silent Disaster): Inverting comparison operators (e.g.
=IF(B2 < C2, "Target Met", "Below Target")). The formula runs perfectly with 0 warnings, but pays bonuses to underperforming employees!
Rule: If Sales (B2) >= Target (C2) return "Target Met", otherwise return "Below Target".
| # | A (Employee) | B (Sales βΉ) | C (Target βΉ) | D (Status) |
|---|---|---|---|---|
| 2 | Amit Sharma | βΉ75,000 | βΉ60,000 | =IF(...) |
| 3 | Priya Patel | βΉ45,000 | βΉ60,000 | =IF(...) |
| 4 | Rahul Verma | βΉ90,000 | βΉ60,000 | =IF(...) |
| 5 | Neha Singh | βΉ55,000 | βΉ60,000 | =IF(...) |