/    /  Amazon QuickSight – sum

Amazon QuickSight – sum

 

The sum() function in Amazon QuickSight is used to calculate the sum of a measure in a dataset. It can also be used with the optional group-by level parameter to calculate the sum of a measure at a particular grouping level.

Syntax

#Start#
sum(measure, [group-by level])
#End#

 

This function takes the following arguments:

 

  • measure: This parameter specifies the measure for which you want to calculate the sum. The measure can be a field or an expression.
  • group-by level: This parameter is optional and is used to specify the grouping level at which you want to calculate the sum. It can be a field or an expression.

 

Suppose you have a sales dataset with the following fields: Date, Product, Sales, and Region. You want to calculate the sum of sales for each region. Here’s an example formula:

 

Example

#Start#
sum(Sales, Region)
#End#

 

This formula calculates the sum of the Sales field for each unique value of the Region field. The Region field is used as the grouping level.

 

If you don’t specify a group-by level, the sum() function will calculate the total sum of the measure across all rows in the dataset. For example, you could calculate the total sum of sales across all regions using the following formula:

 

Example

#Start#
sum(Sales)
#End#

This formula calculates the total sum of the Sales field across all rows in the dataset.

 

You can also use the sum() function with other functions and expressions to calculate more complex calculations. For example, you could calculate the sum of sales values that are greater than the average sales value, using the following formula:

 

Example

#Start#
sum(ifelse(Sales > avg(Sales), Sales, 0))
#End#

 

This formula uses the ifelse() function to create a conditional expression that sets the Sales value to 0 if it is less than or equal to the average sales value, and sets it to the Sales value if it is greater than the average sales value. The sum() function then calculates the sum of these conditional sales values.