Site icon i2tutorials

Amazon QuickSight – switch

Amazon QuickSight – switch

 

The ‘switch’ function in Amazon QuickSight evaluates a given condition-expression against a series of label-expression pairs and returns the value of the corresponding return-expression for the first matching label-expression. If no label-expression matches the condition-expression, the function returns the value of the default-expression.

 

Syntax

 

#Start#
switch(condition-expression, label-1, return-expression-1 [, label-n, return-expression-n ...], 
    default-expression)
#End#

 

This function takes one argument:

 

 

 

Suppose you have a dataset containing sales data for various products, and you want to create a calculated field that assigns a letter grade based on the total sales for each product.

 

Assume the following dataset:

 

Product NameTotal Sales
Product A1500
Product B3000
Product C7500

 

To create a calculated field that assigns a letter grade based on the total sales for each product, you can use the switch function:

 

 

Example

 

#Start#
switch({Total Sales},
    0, "F",
    1000, "D",
    3000, "C",
    5000, "B",
    7500, "A",
    "N/A")
#End#

 

This expression evaluates the {Total Sales} field in the current row against a series of sales thresholds and assigns a corresponding letter grade based on the first matching threshold.

 

 

After creating the calculated field, the dataset would include the following additional column:

 

Product NameTotal SalesSales Grade
Product A1500D
Product B3000C
Product C7500A

 

In this example, the switch function is used to assign a letter grade to each product based on its total sales. The function can be useful for assigning categorical values based on quantitative data.

 

Exit mobile version