Skip to content

SWITCH

The SWITCH function in Infoveave evaluates a condition against an expression and returns a value if the condition is true.

Applicable to

Calculated Columns

Return Value

The SWITCH function returns the specified value if the condition is true.

Remark

The SWITCH function can be used as a more concise alternative to IF statements for simple conditional logic.

Syntax

SWITCH(<expression>, condition, value)

SWITCH in Calculated Columns

ParameterDescription
ExpressionA placeholder in a function that is replaced with the column names.
ConditionThe condition to evaluate against the expression.
ValueThe value to return if the condition is true.

Write the SWITCH function. For instance

SWITCH(<expression>, condition, value)
  1. Replace <expression> with VALUE([Column Name]), replace condition with the actual case that you want to evaluate against expression and replace value with what you expect to return when the condition turns true.Replace the Column Name with the actual name of your column required.
  2. To learn how to add calculated columns in Infoveave, visit the section Calculated Columns.

Example 1

Objective Consider you want to create a pricing bucket to categorize the unit price on the below table.

ORDER DATECOUNTRYCATEGORYUNIT PRICEMARKET PRICEQUANTITY
2024-01-03BrazilBaby Food38.4143.78742
2024-01-07JapanSpices45.5650.815520
Japan43.787410
2024-01-1832.30194
2024-01-22BrazilCosmetics28.33523.01097
2024-01-26Canada20.18523.01099
2024-01-04FranceCereal25.2628.79649
2024-01-09BrazilCereal44.57550.81558
2024-01-14BrazilSnacks20.1854
BrazilCosmetics40.48546.15292

You can use the SWITCH function like

SWITCH(TRUE, VALUE([UNIT PRICE]) > 40, "High Price", VALUE([UNIT PRICE]) < 40 AND VALUE([UNIT PRICE]) > 30 , "Medium Price", "Low Price")

The new calculated column “Price Bucket” will return

ORDER DATECOUNTRYCATEGORYUNIT PRICEMARKET PRICEQUANTITYPRICE BUCKET
03-01-2024BrazilBaby Food38.4143.78742Medium Price
07-01-2024JapanSpices45.5650.815520High Price
Japan43.787410Low Price
18-01-202432.30194Low Price
22-01-2024BrazilCosmetics28.33523.01097Low Price
26-01-2024Canada20.18523.01099Low Price
04-01-2024FranceCereal25.2628.79649Low Price
09-01-2024BrazilCereal44.57550.81558High Price
14-01-2024BrazilSnacks20.1854Low Price
BrazilCosmetics40.48546.15292High Price

Example 2

The SWITCH function in Infoveave can also transform values based on specified conditions.

For example

SWITCH(VALUE([COUNTRY]), "Brazil", "BR", "Japan", "JP", "Canada", "CA", "FRANCE", "FR")

The SWITCH function converts the country names into their respective country codes. For example, if the original value from [COUNTRY] is “Brazil”, the SWITCH function will return “BR”. Similarly, “Japan” will be converted to “JP”, “Canada” to “CA”, and “France” to “FR”. If the value from [COUNTRY] does not match any of the specified conditions, the SWITCH function will return NULL.