FEEL

sum

FEEL built-in function · FEEL list functions

sum(list) or sum(n1, …, nN)

Returns the sum of the numbers. The sum of an empty list is null.

sum takes either one list or several numbers as separate arguments. The two things that surprise people are that an empty list sums to null, not 0, and that one null element makes the whole sum null. Both matter when the list comes from a filter that can match nothing.

To sum a field across a list of contexts, select the field: sum(orders.amount). To sum a computed value, use for.

Parameters

ParameterTypeDescription
listlist of numbersnumbers, as one list or as separate arguments

Examples

sum([1, 2, 3])
sum([])

Edge cases and null handling

sum([1, 2][item > 5])

A filter that matches nothing gives an empty list, and its sum is null, not 0. B-FEEL returns 0.

sum([1, null, 3])
sum([1, null, 3][item != null])
sum([0.1, 0.2])

FEEL numbers are decimal, so there is no floating-point rounding error.

sum(for o in [{price: 2, qty: 3}, {price: 5, qty: 1}] return o.price * o.qty)
sum([duration("PT1H"), duration("PT30M")])

sum only adds numbers; durations give null.

Related functions

mean · product · count

Defined by the OMG DMN 1.6 specification, chapter 10.3.4 (built-in functions).