Functions

# IF

Specifies a logical test to perform.

## Syntax

``````object    IF(bool? condition, object trueValue, object falseValue)
bool      IF(bool? condition, bool trueValue, bool falseValue)
string    IF(bool? condition, string trueValue, string falseValue)
string[]  IF(bool? condition, string[] trueValue, string[] falseValue)
byte?     IF(bool? condition, byte? trueValue, byte? falseValue)
byte[]    IF(bool? condition, byte[] trueValue, byte[] falseValue)
short?    IF(bool? condition, short? trueValue, short? falseValue)
int?      IF(bool? condition, int? trueValue, int? falseValue)
int[]     IF(bool? condition, int[] trueValue, int[] falseValue)
long?     IF(bool? condition, long? trueValue, long? falseValue)
double?   IF(bool? condition, double? trueValue, double? falseValue)
decimal?  IF(bool? condition, decimal? trueValue, decimal? falseValue)
Single?   IF(bool? condition, Single? trueValue, Single? falseValue)
DateTime? IF(bool? condition, DateTime? trueValue, DateTime? falseValue)
Guid?     IF(bool? condition, Guid? trueValue, Guid? falseValue)
``````

## Inputs

Object Description
condition The logical test.
trueValue The value if true.
falseValue The value if false.

## Examples

If Value1 is NULL or an empty string return Value2.

``````IF(ISNULLOREMPTY(Value1), Value2, Value1)
``````

Another example rather than using ISNULLOREMPTY is that you can use the EQUALS function to return either true or false. If the value in Column1 is equal to MyValue then return Value1 otherwise return Value2.

``````IF(EQUALS(Column1, "MyValue"), Value1, Value2)
``````

Alternatively you can also use string literals for the boolean expression rather than equals, but note you must use `==` as these are C# functions. This will only work if your column is a string data type, it can be better to sue the EQUALS function instead. If the value in Column1 is equal to MyValue then return Value1 otherwise return Value2.

``````IF(Column1=="MyValue", Value1, Value2)
``````

For an example of using IF with Lookups, we can take the example of looking up the user account control value in AD. If that is null return a default value otherwise return the value.

``````IF(ISNULL(LOOKUPB("UserAccountControl", "", WHEN("Logon Name", LogonName))), 512, LOOKUPB("UserAccountControl", "", WHEN("Logon Name", LogonName)))
``````