# Sum - chart function

Sum() calculates the total of the values given by the expression or field across the aggregated data.

Syntax:

Sum([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] expr])

Return data type: numeric

Arguments:

Arguments

| Argument | Description |
| --- | --- |
| expr | The expression or field containing the data to be measured. |
| SetExpression | By default, the aggregation function<br>will aggregate over the set of possible records defined by the selection.<br>An alternative set of records can be defined by a set analysis<br>expression. |
| DISTINCT | If the word<br>DISTINCT occurs before the function<br>arguments, duplicates resulting from the evaluation of the function arguments are disregarded.<br><br>Information noteAlthough the DISTINCT qualifier is supported, use it only with extreme caution because it may mislead the reader into thinking a total value is shown when some data has been omitted. |
| TOTAL | If the word<br>TOTAL occurs before the function<br>arguments, the calculation is made over all possible values given<br>the current selections, and not just those that pertain to the current dimensional value, that is, it disregards the chart dimensions.<br><br>By using TOTAL [&lt;fld {.fld}&gt;], where the TOTAL qualifier is followed by a list of one or more field names as a subset of the chart dimension variables, you create a subset of the total possible values.<br><br>[Defining the aggregation scope](https://help.qlik.com/en-US/sense/November2024/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/define-aggregation-scope.htm) |

Examples and results:

Data

| Customer | Product | UnitSales | UnitPrice |
| --- | --- | --- | --- |
| Astrida | AA | 4 | 16 |
| Astrida | AA | 10 | 15 |
| Astrida | BB | 9 | 9 |
| Betacab | BB | 5 | 10 |
| Betacab | CC | 2 | 20 |
| Betacab | DD | - | 25 |
| Canutility | AA | 8 | 15 |
| Canutility | CC | - | 19 |

Examples and results

| Examples | Results |
| --- | --- |
| `Sum(UnitSales)` | 38. The total of the values in `UnitSales`. |
| `Sum(UnitSales*UnitPrice)` | 505. The total of `UnitPrice` multiplied by `UnitSales` aggregated. |
| `Sum(TOTAL UnitSales*UnitPrice)` | 505 for all rows in the table as well as the total, because the TOTAL qualifier means the sum is still 505, disregarding the chart dimensions. |
| Make the selection`  Customer B `.<br><br>`Sum({1} TOTAL UnitSales*UnitPrice)` | 505, independent of the selection made, because the Set Analysis expression {1} defines the set of records to be evaluated as ALL, no matter what selection is made. |

Data used in examples:

`ProductData:` `LOAD * inline [` `Customer|Product|UnitSales|UnitPrice` `Astrida|AA|4|16` `Astrida|AA|10|15` `Astrida|BB|9|9` `Betacab|BB|5|10` `Betacab|CC|2|20` `Betacab|DD||25` `Canutility|AA|8|15` `Canutility|CC||19` `] (delimiter is '|');`

## Learn more

* [Set analysis](https://help.qlik.com/en-US/sense/November2024/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/SetAnalysis/set-analysis-expressions.htm)
* [Defining the aggregation scope](https://help.qlik.com/en-US/sense/November2024/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/define-aggregation-scope.htm)