/    /  Amazon QuickSight – Ifelse

Amazon QuickSight – Ifelse

 

In Amazon QuickSight, the ifelse function is used in calculated fields to perform conditional evaluations and return different results based on the conditions met.

Syntax

#Start#
ifelse(if-expression-1, then-expression-1 [, if-expression-2, then-expression-2, ...], else-expression)
#End#

 

This function takes four arguments

 

  • if-expression-1: The first condition to evaluate. This can be any expression that returns a logical (Boolean) value (TRUE or FALSE).
  • then-expression-1: The value to return if if-expression-1 is TRUE.
  • if-expression-2, then-expression-2, and so on: Additional conditions and values to evaluate if the preceding condition(s) are FALSE. You can include as many of these pairs as you need.
  • else-expression: The value to return if none of the conditions are TRUE. This is optional but recommended because it ensures that the function always returns a value.

 

Example

#Start#
ifelse({OrderAmount} < 100, "Low", 
       ifelse({OrderAmount} < 500, "Medium", "High"))
#End#

 

In this example, the ifelse function evaluates each value in the OrderAmount field and categorizes it as “Low”, “Medium”, or “High” based on its value. The first condition checks if the value is less than 100, the second condition checks if it’s less than 500 (but greater than or equal to 100), and the final condition checks if it’s greater than or equal to 500. If none of these conditions are true, the function returns null. The resulting field contains the corresponding categories for each value in the OrderAmount field.