Feature: Include array elements conditionally with IF

Use IF to determine if an element should be part of an array.

The IF function has special behavior when used inside of arrays. Specifically, if its third parameter is not given, it can be used to determine if array elements should be part of the array.

This can be very useful at times. The IncludedFields property of a reset button is used to determine what fields are reset by the button. This formula makes sure that Field1 is always reset, but Field2 is only reset if the value of Field1 is greater than 4:

{ Field1, IF(Field1 > 4, Field2) }{ Field1; IF(Field1 > 4; Field2) }

In other words, the returned array is { Field1 }{ Field1 } if the value of Field1 is not greater than 4. Otherwise, the returned array is { Field1, Field2 }{ Field1; Field2 }.

Not including the third parameter to IF causes it to return a blank value. That means that these formulas are typically equivalent:

IF(Field1 > 4, Field2)IF(Field1 > 4; Field2)
IF(Field1 > 4, Field2, BLANK())IF(Field1 > 4; Field2; BLANK())

However, these formulas are not equivalent:

{ Field1, IF(Field1 > 4, Field2) }{ Field1; IF(Field1 > 4; Field2) }
{ Field1, IF(Field1 > 4, Field2, BLANK()) }{ Field1; IF(Field1 > 4; Field2; BLANK()) }

If the value of Field1 is not greater than 4, the first formula above returns the array { Field1 }{ Field1 } (without Field2). However, the second formula above returns the array { Field1, BLANK() }{ Field1; BLANK() }.

In other words, when you construct an array and use IF to include elements conditionally, only set the third parameter to BLANK()BLANK() if you want a blank value to be part of your array if the condition does not hold. If you want to leave out the element completely, leave out the third IF parameter.

« Feature: Join arrays together with | Feature: Download and start large apps faster »