# Sum - script function

Sum() calculates the total of the values aggregated in the expression, as defined by a group by clause.

Syntax:

sum ( [ distinct] expr)

Return data type: numeric

Arguments:

Sum arguments

| Argument | Description |
| --- | --- |
| distinct | If the word distinct<br>occurs before the expression, all duplicates will be disregarded. |
| expr | The expression or field containing the data to be measured. |

Examples and results:

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

`Temp:` `LOAD * inline [` `Customer|Product|OrderNumber|UnitSales|CustomerID` `Astrida|AA|1|10|1` `Astrida|AA|7|18|1` `Astrida|BB|4|9|1` `Astrida|CC|6|2|1` `Betacab|AA|5|4|2` `Betacab|BB|2|5|2` `Betacab|DD` `Canutility|DD|3|8` `Canutility|CC` `] (delimiter is '|');` ` ` `Sum:` `LOAD Customer, Sum(UnitSales) as MySum  Resident Temp Group By Customer;`

Example 1 results

| Result field (Customer) | Result value (MySum) |
| --- | --- |
| Astrida | 39 |
| Betacab | 9 |
| Canutility | 8 |