Conditional Functions

Version:
Current
Last modified: June 26, 2020

A conditional function performs an action or calculation based on a test of data using an IF statement. Use a conditional function to provide a TRUE or FALSE result to highlight or filter out data based on specific criteria. Conditional functions can be used with any data type. 

Consider each conditional function before writing your test. Some conditional functions are better suited to specific use cases.

IF c THEN t ELSE f ENDIF

IF c THEN t ELSE f ENDIF: Returns t if the condition c is true, else returns f.

Example

IF [Class]==1 THEN "Gold" ELSE "Other" ENDIF

Class Result
1 Gold
2 Other
1 Gold
3 Other

IF c THEN t ELSEIF c2 THEN t2 ELSE f ENDIF

IF c THEN t ELSEIF c2 THEN t2 ELSE f ENDIF: Returns t if the first condition c is true, else returns t2 if the second condition c2 is true, else returns f.

Multiple ELSEIF statements can be included.

Example

IF [Class]==1 THEN "Gold" ELSEIF [Class]==2 THEN "Silver" ELSE "Other" ENDIF

Class Result
1 Gold
2 Silver
1 Gold
3 Other

IIF

IIF(bool, x, y): Returns x if bool is true, else returns y.

Example

IIF([CUSTOMER], "Send flyer", "Send documentation")

If the [CUSTOMER] field value is TRUE, then it returns Send flyer.

If the [CUSTOMER] field value is FALSE, then it returns Send documentation.

Switch

Switch(Value,Default,Case1,Result1,...,CaseN,ResultN): Compares a value against a list of cases and returns the corresponding result.

Example

Switch([Class], Null(), "Gold",1,"Silver",2,"Bronze", 3,"Tin", 4, "Aluminum",5)

Result Class
5 Aluminum
2 Silver
1 Gold
3 Bronze
4 Tin
2 Silver
1 Gold
Null Other
Was This Helpful?

Running into problems or issues with your Alteryx product? Visit the Alteryx Community or contact support.