The IF function
The decision function: if the condition is true, one value; otherwise, another. Things get complicated when they are nested.
Syntax
=IF(logical_test, value_if_true, [value_if_false])
In a French Excel: =SI(test_logique; valeur_si_vrai; [valeur_si_faux]).
Arguments
- logical_test: a comparison that is TRUE or FALSE, such as
B2>1000. - value_if_true: what to return if it is true.
- value_if_false: what to return otherwise; omitted, IF returns FALSE.
An example
=IF(AND(B2>=1000,C2="Delivered"),"Bonus","")
Returns "Bonus" if the amount reaches 1,000 and the order is delivered; an empty cell otherwise. AND requires both conditions, OR would settle for one.
Pitfalls
Going further
- IFS, for several cases.
- IFERROR, to replace an error.
- Find the right formula: "show a result based on a condition".
Frequently asked questions
- How many IFs can be nested?
- Up to 64, but beyond three the formula becomes hard to read and fix: IFS or a lookup table with XLOOKUP are safer.