IF function

Returns one value if a logical expression is `TRUE` and another if it is `FALSE`.

Sample Usage

IF(A2 = "foo","A2 is foo")

IF(A2,"A2 was true","A2 was false")

IF(TRUE,4,5)

Syntax

IF(logical_expression, value_if_true, value_if_false)

  • logical_expression - An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE.
  • value_if_true - The value the function returns if logical_expression is TRUE.
  • value_if_false - [ OPTIONAL - blank by default ] - The value the function returns if logical_expression is FALSE.

Notes

  • Ensure that value_if_true and value_if_false are provided to the function in the correct order - this is the single most common source of problems with IF.Examples

Specifies a logical test to be performed.

Result

Formula



True_Value

=IF(1=1, "True_Value", "False_Value")



Smaller

=IF(-1>0, "Greater", "Smaller")



Equal

=IF("Google"="google", "Equal", "Unequal")




=IF(TRUE, , "False")




=IF(FALSE, "True", )



Nested_Outcome

=IF( IF(1>0, TRUE, FALSE), "Nested_Outcome", IF(TRUE, "Reached", "Unreached") )