IF Function

Makes a decision: one result if a test is TRUE, another if it's FALSE.

Category

Logical

Available in

All versions, Microsoft 365

Returns

Whatever you tell it to return for TRUE or FALSE

Taught hands-on in Level 2: Essential Formulas & Everyday Logic - Logical Functions module

Overview

IF is Excel's decision-maker. You give it a question that can only be answered TRUE or FALSE — like B2>=500 — and tell it what to return in each case.

It's the foundation for bonuses, pass/fail flags, tiered pricing and hiding unwanted results. Once IF clicks, AND, OR, IFS and IFERROR follow naturally.

Syntax

=IF(logical_test, value_if_true, [value_if_false])

Arguments

ArgumentRequired?What it does
logical_testYesAny comparison or value that works out to TRUE or FALSE, such as B2>=500 or C2="Closed".
value_if_trueYesWhat to return when the test is TRUE — text, a number, a cell or another formula.
value_if_falseOptionalWhat to return when the test is FALSE. Leave it out and IF returns FALSE.

Examples

Example 1 — Did the rep hit target?

Northstar pays a bonus when monthly sales reach 500. Flag each rep with Yes or No.

C2fx=IF(B2>=500, "Yes", "No")
ABC
1RepSalesBonus?
2Ana620Yes
3Ben480No
4Cara500Yes
5Dev350No
=IF(B2>=500, "Yes", "No") Explain

Cara's 500 counts because >= means “greater than or equal to”. Use > if exactly 500 shouldn't qualify.

Example 2 — Calculating, not just labelling

Pay 10% commission on sales of 500 or more, otherwise nothing.

C2fx=IF(B2>=500, B2*10%, 0)
ABC
1RepSalesCommission
2Ana62062
3Ben4800
4Cara50050
5Dev3500
=IF(B2>=500, B2*10%, 0) Explain
Keep the 500 and the 10% in their own cells (say F1 and F2) and write =IF(B2>=$F$1, B2*$F$2, 0). Changing the rule then never means editing formulas.

Example 3 — Nested IF for three outcomes

Grade a score as A (90+), B (80+) or C (anything lower).

=IF(B2>=90, "A", IF(B2>=80, "B", "C")) Explain
  1. Excel checks B2>=90 first. If TRUE, the answer is A and it stops.
  2. If not, the second IF checks B2>=80 and returns B.
  3. Anything left falls through to C.
With more than two or three levels, IFS reads far more cleanly than nested IFs.

Example 4 — Leaving a cell blank

Only calculate tax once a price has been entered.

=IF(B2="", "", B2*1.13) Explain

Two double quotes "" mean “empty text”, so the cell looks blank until B2 is filled in.

Common mistakes

  • Text without quotes. Text results must be in double quotes: "Yes", not Yes. Without them Excel looks for a named range and returns #NAME?.
  • Numbers in quotes. Writing "500" turns the number into text, so B2>="500" compares the wrong way. Leave numbers unquoted.
  • Tests in the wrong order. In nested IFs the first TRUE test wins. Check the highest threshold first, or every score lands in the first band.
  • An unexpected FALSE. You left out value_if_false and the test failed. Add a third argument, even if it's just "".

Notes

  • A comparison on its own already returns TRUE/FALSE: =B2>=500 works without IF if TRUE/FALSE is all you need.
  • Related functions: IFS, AND, OR, NOT, SWITCH, IFERROR.
Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.