If

Syntax

If(TestExpression1, ResultIfTrue1, ..., TestExpressionN, ResultIfTrueN, ResultIfAllFalse)

Description

The If function evaluates each TestExpression in sequence, and for the first one that is not FALSE (<> 0), returns the value of its associated ResultIfTrue. If all TestExpressions are FALSE, then the value of ResultIfAllFalse is returned, or 0 if ResultIfAllFalse is omitted.

TestExpression is any value or expression that can be evaluated to TRUE or FALSE. Test expressions are generally made up of two or more terms which are compared according to standard logical operators. If there are more than one TestExpression, they are evaluated in order from left to right until the first TRUE one is found.

ResultIfTrue1 is an expression that is evaluated if TestExpression1 is TRUE (<>0).

ResultIfFalse is an expression that is evaluated if all TestExpressions are FALSE (=0).

Examples

If(Income > 1000, 10, 20)
If the branch named Income has a value greater than 1000 then the function evaluates to 10. Otherwise, is it 20.

If( year >= 2005, 30, 0)
= 30 in years 2005 and after, 0 before 2005

If( year < 2005, 0, year < 2010, 10, year < 2020, 15, 20)
= 0 in years before 2005, 10 in years 2005-2009, 15 in 2010-2019, and 20 in years 2020 and after.