How to Use the IF Function in Excel: Syntax, Examples and Common Errors

Excel IF function tutorial cover

What is the IF function in Excel?

The IF function checks a logical condition and returns one result when it is TRUE and another when it is FALSE. It is useful for pass/fail scores, payment status, sales targets and exception reports. For beginners, one IF statement is usually easier to understand than a deeply nested formula.

Excel IF syntax

=IF(logical_test,value_if_true,value_if_false)

logical_test is a comparison such as B2>=50. value_if_true is the answer when the condition passes; value_if_false is returned otherwise. Text results need double quotes, but numbers do not.

Example 1: Pass or fail marks

With a student’s score of 72 in B2, a pass mark of 50 is checked by:

=IF(B2>=50,"Pass","Fail")

Result: Pass. Change B2 to 43 and the result becomes Fail. The comparison includes exactly 50 because it uses >= rather than >.

Example 2: Sales target achieved

If C2 contains actual sales of 82,000 and D2 contains a target of 75,000:

=IF(C2>=D2,"Target met","Below target")

Result: Target met. Using D2 as a reference makes the same formula reusable for different employees with different targets.

Example 3: Calculate a conditional bonus

Suppose B2 contains sales of 60,000. Pay a 5% bonus only when sales are at least 50,000:

=IF(B2>=50000,B2*5%,0)

Result: 3,000. The calculation is performed only when the condition is met.

Example 4: Flag overdue invoices

Let A2 be the due date and B2 be a payment-status cell. Mark an unpaid invoice as overdue if the due date has passed:

=IF(AND(A2<TODAY(),B2="Unpaid"),"Overdue","Not overdue")

This uses AND so both conditions must be TRUE. The date in A2 must be a real Excel date, not text.

Example 5: Nested IF for grades

With a score in B2:

=IF(B2>=80,"A",IF(B2>=60,"B",IF(B2>=40,"C","D")))

A score of 74 returns B. Read the tests from highest to lowest. For many categories, the IFS function may be easier to maintain.

Example 6: Leave blank when no value has been entered

=IF(B2="","",IF(B2>=50,"Pass","Fail"))

This avoids showing Fail for an unfilled score cell. It also treats an empty string returned by a formula as blank.

IF versus IFS

IF chooses between two paths and can be nested. IFS checks multiple conditions in order and returns the result for the first TRUE condition. IFS does not automatically provide a final default unless you add a TRUE condition.

Common IF formula mistakes

  • Unquoted text: use "Pass" rather than Pass.
  • Incorrect operator: > excludes the threshold; >= includes it.
  • Mixed types: dates and numbers stored as text may produce unexpected comparisons.
  • Too many nested levels: consider IFS or a lookup table for long grading rules.
  • Separators: some regional Excel settings use semicolons instead of commas.

Frequently asked questions

Can IF return a number instead of text?

Yes. For example, =IF(A2>0,1,0) returns numeric 1 or 0.

Can IF test more than one condition?

Yes. Combine it with AND or OR to test several comparisons together.

How do I avoid a result for an empty cell?

Check for an empty cell first: =IF(A2="","",IF(A2>=50,"Pass","Fail")).

Practice exercise

Make a table of ten students with their marks. Return Pass if marks are at least 50. Add a separate column that awards a certificate when marks are at least 75. Then use an input cell to change the pass mark.

Related Excel tutorials

Continue learning with Module 3: Excel Functions, IFERROR examples, or explore related conditions and lookup functions across the Excel tutorial library.

Official reference

For exact syntax and version-specific information, consult Microsoft Excel Support.