Excel IF Function
The IF function can perform a logical test and return one value for a TRUE result, and another for a FALSE result. For example, to "pass" scores above 70: =IF(A1>70,"Pass","Fail"). More than one condition can be tested by nesting IF functions. The IF function can be combined with logical functions like AND and OR.
- logical_test - A value or logical expression that can be evaluated as TRUE or FALSE.
- value_if_true - [optional] The value to return when logical_test evaluates to TRUE.
- value_if_false - [optional] The value to return when logical_test evaluates to FALSE.
Use the IF function to test for or evaluate certain conditions, and then react differently depending on whether the test was TRUE or FALSE.
In the example shown, we want to assign either "Pass" or "Fail" based on a test score. A passing score is 70 or higher. The formula in D6, copied down, is:
Translation: If the value in C6 is greater than or equal to 70, return "Pass". Otherwise, return "Fail".
The logical flow this formula could be reversed. A formula with the same result could be written like this:
Translation: If the value in C6 is less than 70, return "Fail". Otherwise, return "Pass".
Either formula above, when copied down the column, will test every score and return the correct result.
Note: If you are new to the idea of formula criteria, this article shows many examples.
Nested IF statements
The IF function can be "nested". A "nested IF" refers to a formula where at least one IF function is nested inside another in order to test for more conditions and return more possible results. Each IF statement needs to be carefully "nested" inside another so that the logic is correct.
For example, the following formula can be used to assign an grade rather than a pass / fail result:
Up to 64 IF functions can be nested. However, in general, you should consider other functions, like VLOOKUP or HLOOKUP for more complex scenarios, because they can handle more conditions in much more streamlined fashion.
When you are constructing a test with IF, you can use any of the following logical operators:
|>=||greater than or equal to||A1>=D1|
|<=||less than or equal to||A1<=D1|
|<>||not equal to||A1<>D1|
- Read more about nested IFs
- Learn how to use VLOOKUP instead of nested IFs (video)
- 50 Examples of formula criteria