Skip to main content

$$avg

Returns the average of all values in the array

Usage​

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

Returns​

BigDecimal

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray to average
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]
"$$avg:$"
4.86
[4, 2, 13.45, null]
"$$avg(1):$"
5.11
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$avg": "$",
"by": "##current.value"
}
4.86
[
{ "value": 4 },
{ "value": 2 },
{ "value": 13.45 },
{ "value": null }
]
{
"$$avg": "$",
"by": "##current.value",
"default": 1
}
5.11