Skip to main content

$$avg

Returns the average of all values in the array

Usage​

{ 
"$$avg": /* Array to average */,
"default": 0 /* BigDecimal */,
"by": "##current" /* Transformer(##current) */
}
"$$avg([default],[by]):{input}"
note

Concrete values in the usage example are default values.

Returns​

number (BigDecimal)

Arguments​

ArgumentTypeValuesRequired / Default ValueDescription
PrimaryarrayYesArray to average
defaultBigDecimal0The default value to use for empty values
byTransformer(##current)##currentA transformer to extract a property to sum by (using ##current to refer to the current item)
  • ##current - Current element

Examples​

Input

Definition

Output

[
4,
2,
13.45,
null
]
"$$avg():$"
4.8625
[
4,
2,
13.45,
null
]
"$$avg(1):$"
5.1125
[
{
"value": 4
},
{
"value": 2
},
{
"value": 13.45
},
{
"value": null
}
]
{
"$$avg": "$",
"by": "##current.value"
}
4.8625
[
{
"value": 4
},
{
"value": 2
},
{
"value": 13.45
},
{
"value": null
}
]
{
"$$avg": "$",
"by": "##current.value",
"default": 1
}
5.1125