ID EN
#Logical

IF

Excel Functions

Test for a specific condition

Syntax

EXCEL
=IF(logical_test, [value_if_true], [value_if_false])

Arguments

Parameter Description
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.

Return Value

The values you supply for TRUE or FALSE

Details

The IF function is one of the most widely used functions in Excel. At the core, IF runs a test and returns one value when the result is TRUE, and another value when the result is FALSE. At first glance, this seems very basic — if this is true, do this; otherwise, do that. However, formulas that use IF can quickly become advanced as the requirements become more complex and more IFs are nested together. One of the tricks in using IF effectively is knowing how to combine IF with other functions like AND and OR to handle more complex logic gracefully. This article explains the basics carefully, then introduces more advanced formulas that use the IF function. To understand how the IF function works, let's start with a very basic example. In the worksheet below, the goal is to use the IF functio

Examples

Basic IF function example

To understand how the IF function works, let's start with a very basic example. In the worksheet below, the goal is to use the IF function to mark sco

EXCEL
=IF(B5>80,TRUE)
Basic IF function example

Note we are not using quotes ("") anywhere in the formula because the formula contains no text. Also, we do not need to provide a value for value_if_f

EXCEL
=IF(B5>80,"x")
Basic IF function example

Note that TRUE values have been replaced by "x", and the FALSE results remain FALSE since we have not provided a value for value_if_false. Finally, le

EXCEL
=IF(B5>80,"x","")
Example - Pass or Fail

In the worksheet below, we want to assign either a "Pass" or "Fail" based on a test score. A passing score is 70 or higher. The formula in E5, copied

EXCEL
=IF(C5<70,"Fail","Pass")
Example - Pass or Fail

Notice both "Pass" and "Fail" are in double quotes ("") because they are text values. Also, note that the logical flow of this formula can be reversed

EXCEL
=IF(C5>=70,"Pass","Fail")
Example - IF this OR that

A common challenge with the IF function is how to handle a problem that requires "if this or that" logic. The logical test for IF takes just one value

EXCEL
=IF(OR(B5="red",B5="green"),"x","")

See Also

AND OR NOT IFS SWITCH