count function

The count function returns the number of times each distinct value is present in an attribute.

In its most simple form, count(), it can also be used to simply count the number of overall values in an attribute.


Parameters

count(group)

Parameter

Description

group

The attribute by which you want to group results.

A list of attributes can also be provided in the column parameter, as long as they are enclosed in double brackets, i.e. count((column1, column2)), or as a range of values, divided by a colon, i.e. count(column1 : column5).


Example - count

The following example uses the Bike Sales dataset.

Description

Screenshot

In the example, we want to fill the count attribute with the number of overall values in the attribute.

We simply write the formula count() and the attribute will be filled with the number of values, which in this example is 113036.

If we want to count the number times distinct values are present in the Country attribute, enter Country in the column parameter.

The formula to write will be: count($"Country")

The results show us that Canada is present in the Country attribute 14178 times, while Australia is present 23936 times, and so on.

If we want to group the Country results by a State, we can enter both attributes as a list in the column parameter.

The formula to write will be:count(($"Country", $"State"))

The results can be read as follows:

  • The number of times in the dataset where the Country attribute is Australia and the State attribute is New South Wales is 10412;

  • The number of times in the dataset that the Country attribute is Australia and the State attribute is Victoria is 6016.