Amazon QuickSight – count
The count function in Amazon QuickSight is an aggregate function that counts the number of rows in a dataset that contains a specified dimension or measure. It takes one required parameter, the dimension or measures to count, and one optional parameter, the level at which to group the data.
Syntax
#Start# count(dimension-or-measure, [group-by level]) #End#
This function takes two arguments
- dimension-or-measure: The dimension or measure to count. You can use column names, constants, or other expressions as inputs.
- group-by level: (Optional) The level at which to group the data. 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.
You could use the following expression to count the number of sales made in the East region.
Example
#Start# countIf({Sales}, {Region} = "East" and {Year} = 2021) #End#
This expression counts the number of rows in the dataset where the Region column is equal to “East” and the Year column is equal to 2021. The result would be a single number that represents the count of sales made in the East region in the year 2021.
For example, if the dataset contains the following data:
| Region | Sales | Year |
| East | 100 | 2020 |
| East | 200 | 2021 |
| West | 150 | 2021 |
| West | 300 | 2020 |
The result of the expression would be the value 1, which represents the number of rows in the dataset where the Region is East and the Year is 2021. The countIf function simply counts the number of rows that meet the specified condition, which is 1 in this case.