# sum

Returns the sum of numeric values in an iterative context.

The sum function returns the sum of numeric values across multiple rows in an iterative context, such as with a GROUP BY clause or in a FROM-SELECT query.

To calculate the sum of values in an array or collection, use the arraySum function instead.

## Arguments

Expression returning a numeric value.

## Examples

Calculate the total price across all orders:

```
FROM order
SELECT sum(price)
```

Calculate the total quantity per order:

```
FROM order UNNEST items
GROUP BY order_id
SELECT {
  order_id,
  total_quantity = sum(quantity)
}
```

## Related functions

* [arraySum](https://help.qlik.com/talend/en-US/data-shaping-language-reference-guide/8.0/arraysum-function) - Calculates the sum of values in an array
* [avg](https://help.qlik.com/talend/en-US/data-shaping-language-reference-guide/8.0/avg-function) - Calculates the average in an iterative context