Skip to main content

Count - script function

Count() returns the number of values aggregated in expression, as defined by a group by clause.

Syntax:  

Count( [distinct ] expr)

Return data type: integer

Arguments:  

Arguments
Argument Description
expr The expression or field containing the data to be measured.
distinct If the word distinct occurs before the expression, all duplicates are disregarded.

Examples and results:  

Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in our app to see the result.

To get the same look as in the result column below, in the properties panel, under Sorting, switch from Auto to Custom, then deselect numerical and alphabetical sorting.

Scripting examples
Example Result

Temp:

LOAD * inline [

Customer|Product|OrderNumber|UnitSales|UnitPrice

Astrida|AA|1|4|16

Astrida|AA|7|10|15

Astrida|BB|4|9|9

Betacab|CC|6|5|10

Betacab|AA|5|2|20

Betacab|BB|1|25| 25

Canutility|AA|3|8|15

Canutility|CC|||19

Divadip|CC|2|4|16

Divadip|DD|3|1|25

] (delimiter is '|');

 

Count1:

LOAD Customer,Count(OrderNumber) as OrdersByCustomer Resident Temp Group By Customer;

Customer OrdersByCustomer

Astrida 3

Betacab 3

Canutility 2

Divadip 2

As long as the dimension Customer is included in the table on the sheet, otherwise the result for OrdersByCustomer is 3, 2.

Given that the Temp table is loaded as in the previous example:

LOAD Count(OrderNumber) as TotalOrderNumber Resident Temp;

TotalOrderNumber

10

Given that the Temp table is loaded as in the first example:

LOAD Count(distinct OrderNumber) as TotalOrderNumber Resident Temp;

TotalOrderNumber

8

Because there are two values of OrderNumber with the same value, 1, and one null value.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!