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
- dimension-or-measure: The dimension or measure to count the unique values for. You can use column names, constants, or other expressions as inputs.
- [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
| Region | Sales | Product |
| East | 100 | A |
| East | 200 | B |
| West | 150 | A |
| West | 300 | C |
The result of the expression would be the following table:
| Region | Sales |
| East | 2 |
| West | 2 |
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.