/    /  Amazon QuickSight – distinct_count

Amazon QuickSight – distinct_count 

 

The distinct_count function in Amazon QuickSight is an aggregate function that counts the number of unique values in a dataset for a specified dimension or measure, optionally grouped by one or more dimensions. 

Syntax

#Start#
distinct_count(dimension-or-measure, [group-by level])
#End#

 

This function takes one or two parameters

  1. dimension-or-measure: The dimension or measure to count the unique values for. You can use column names, constants, or other expressions as inputs.
  2. [group-by level]: (Optional) A dimension or a list of dimensions to group the data by before counting the unique values. You can use column names, constants, or other expressions as inputs.

Suppose you have a dataset that contains information about the sales of a company in different regions. 

The dataset has the following columns:

 

  • Region: The name of the region where the sales were made.
  • Sales: The total sales for each region.
  • Year: The year in which the sales were made.

To count the number of unique products sold in each region, you could use the following expression.

Example

#Start#
distinct_count({Product}, {Region})
#End#

 

This expression counts the number of unique values in the Product column of the dataset for each unique value in the Region column. The result would be a table that shows the count of unique products sold in each region.

 

For example, if the dataset contains the following data

RegionSalesProduct
East100A
East200B
West150A
West300C

 

The result of the expression would be the following table:

RegionSales
East2
West2

 

This table shows that there are two unique products sold in the East region and two unique products sold in the West region. The distinct_count function is used to count the number of unique values in the Product column, and the results are grouped by the Region column.