IF Function
The Excel IF function evaluates a logical test and returns one result when the test is true and another when it is false. Its result branches can contain text, numbers, references, or calculations.
| Excel IF Function | |||||||
| Change the cream values to see how IF returns one result when a test is true and another when it is false. | |||||||
| Source scenarios, editable | IF examples | ||||||
| Scenario | Test Value | Comparison Value | Data Note | Example | Formula syntax | Result | |
| Score threshold | 82 | 70 | True branch expected | Threshold status | =IF(B12>=C12,"Pass","Review") | Pass | |
| Positive number | -5 | 0 | False branch expected | Sign classification | =IF(B13>0,"Positive","Zero or negative") | Zero or negative | |
| Required entry | True blank | Blank status | =IF(B14="","Missing","Entered") | Missing | |||
| Text match | Ready | Ready | Equal text values | Text match status | =IF(B15=C15,"Match","Different") | Match | |
| Amount above target | 120 | 100 | Calculated true branch | Amount above target | =IF(B16>=C16,B16-C16,0) | 20 | |
| How IF chooses a result | |||||||
| The logical test is evaluated first and resolves to TRUE or FALSE. | |||||||
| IF returns only the matching true or false branch; text results need quotation marks. | |||||||
| Branches can return text, numbers, references, or calculations. | |||||||
| Reliability checks | |||||||
| Threshold example returns Pass for 82 against 70 | OK | ||||||
| Calculated branch returns the amount above target | OK | ||||||
Overview
The Excel IF function turns a true-or-false test into a result. It evaluates one condition, follows the true branch when that condition passes, and follows the false branch when it does not.
Quick reference
Syntax: =IF(logical_test, [value_if_true], [value_if_false])
Returns: The value assigned to the branch matching the logical test result. (varies)
Arguments:
logical_test(required) — A value or expression that Excel evaluates as TRUE or FALSE.value_if_true(optional) — The value, reference, or calculation returned when the test is TRUE.value_if_false(optional) — The value, reference, or calculation returned when the test is FALSE.
The bracketed value_if_false argument is optional. When it is omitted and the logical test is false, Excel returns FALSE; supply both result arguments when the formula must return controlled outputs in either branch.
Common uses
- Label results as pass, review, complete, missing, or another status.
- Return different calculations above and below a threshold.
- Check whether a cell is blank or whether two values match.
- Prevent a calculation from running when its prerequisites are not met.
Calculations
Excel evaluates logical_test first. Comparison operators such as =, <>, >, >=, <, and <= create tests that resolve to TRUE or FALSE. IF then returns the matching branch.
Literal text results must be enclosed in quotation marks. Numbers, cell references, and calculations do not need quotes. The two branches may also return different data types, although consistent result types are usually easier to use downstream.
A blank comparison such as B14="" detects a true blank and also evaluates as true for a formula-generated empty string. Deeply nested IF formulas can become difficult to audit; functions such as AND, OR, IFS, SWITCH, and lookup functions often express larger decision rules more clearly.
Function behavior
Situation | Behavior |
|---|---|
Test is TRUE | Returns |
Test is FALSE | Returns |
Text result | Literal text must be enclosed in quotation marks. |
Blank comparison | |
Calculation branch | The selected branch can return the result of a calculation. |
Error in the test | The error propagates unless it is handled separately. |
Common errors
Omitting quotation marks around text
What happens:
Excel interprets an unquoted word as a name or reference and may return #NAME?.
Better approach:
Enclose literal text results and text criteria in double quotation marks.
Reversing the true and false branches
What happens:
The formula returns the opposite result from the intended rule.
Better approach:
Read the formula as: if this test is true, return the second argument; otherwise return the third.
Building deeply nested IF formulas
What happens:
The decision order becomes difficult to audit and maintain.
Better approach:
Use AND or OR to combine tests, IFS or SWITCH for multiple branches, or a lookup table for mapped results.
Example
Example 1 — Test a Threshold
=IF(B12>=C12,"Pass","Review")
The score is 82 and the threshold is 70, so the test is true and the formula returns Pass.
Example 2 — Classify a Number
=IF(B13>0,"Positive","Zero or negative")
The sample value is -5. Because it is not greater than zero, the false branch returns Zero or negative.
Example 3 — Check for a Blank
=IF(B14="","Missing","Entered")
Cell B14 is empty, so the test returns true and the result is Missing.
Example workbook
The workbook contains IF Example and Notes tabs. Five live scenarios demonstrate a threshold, sign classification, blank check, text match, and calculated branch. Two checks confirm the threshold and calculated results.
Key takeaway
IF evaluates one logical test and returns only the result assigned to the matching true or false branch.