Skip to main content

$$sum

Returns a sum of all values in the array

Usage​

{
"$$sum": [ /* values */ ],
"by": /* Transformer */
"default": /* 0 */
}
"$$sum([default],[by]):{input}"

Returns​

BigDecimal

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray to sum
defaultBigDecimal0The default value to use for empty values
byTransformer(##current)Input is ##current (current element)"##current"A transformer to extract a property to sum by (using ##current to refer to the current item)

Examples​

Input

Definition

Output

[4, 2, 13.45, null]
"$$sum:$"
19.45
[4, 2, 13.45, null]
"$$sum(1):$"
20.45
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$sum": "$",
"by": "##current.value"
}
19.45
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$sum": "$",
"by": "##current.value",
"default": 1
}
20.45