# Conditional Functions

Version:
2021.2

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

In this example, we pass in the column "Class" where the values are various types of metals. In the function, we then define the case and result for each type of metal.

When we run the function, the function reads the value in the "Class" column. It then looks for that value in the list of cases and if a match is found, it returns the result associated with that case. For example, if the value is "Silver", the function looks for "Silver" in the list of cases and returns the corresponding result, 2 in this case.

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

Class Result
Aluminum 5
Silver 2
Gold 1
Bronze 3
Tin 4
Silver 2
Gold 1
Other Null

Running into problems or issues with your Alteryx product? Visit the Alteryx Community or contact support. Can't submit this form? Email us.