# Count - Script function

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

Syntax:

Count(Count( [distinctdistinct ] expr ] 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<br>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:`<br>`LOAD * inline [`<br>`Customer\|Product\|OrderNumber\|UnitSales\|UnitPrice`<br>`Astrida\|AA\|1\|4\|16`<br>`Astrida\|AA\|7\|10\|15`<br>`Astrida\|BB\|4\|9\|9`<br>`Betacab\|CC\|6\|5\|10`<br>`Betacab\|AA\|5\|2\|20`<br>`Betacab\|BB\|1\|25\|  25`<br>`Canutility\|AA\|3\|8\|15`<br>`Canutility\|CC\|\|\|19`<br>`Divadip\|CC\|2\|4\|16`<br>`Divadip\|DD\|3\|1\|25`<br>`] (delimiter is '\|');`<br><br>`Count1:`<br>`LOAD Customer,Count(OrderNumber) as OrdersByCustomer Resident Temp Group By Customer;<br>` | `Customer OrdersByCustomer`<br>`Astrida 3`<br>`Betacab 3`<br>`Canutility 2`<br>`Divadip 2`<br><br>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:<br><br>`LOAD  Count(OrderNumber) as TotalOrderNumber Resident Temp;` | ` TotalOrderNumber  `<br>`10` |
| Given that the Temp table is loaded as in the first example:<br><br>`LOAD  Count(distinct OrderNumber) as TotalOrderNumber Resident Temp;` | ` TotalOrderNumber  `<br>`8`<br><br>Because there are two values of OrderNumber with the same value, 1, and one null value. |