avg( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Refines a WixDataAggregate to only contain the average value from each aggregation group.

The avg() method refines a WixDataAggregate to contain the average value from the specified field for each aggregated group or from the whole collection if no group is defined.

When the aggregation is run(), the returned WixDataAggregateResult object contains an item for each group with the following key:value pairs:

  • If a value was passed for the optional projectedField, the key is named using that value. Otherwise, the key is named using the following format: "fieldAvg", where field is the name of the specified field.
  • The value is the average of the values found in the specified field.

Averages can only be calculated on fields of type Number.

Note: Aggregations can only be used on collections you have created. They cannot be used on Wix app collections.

Method Declaration
Copy
Method Parameters
fieldstringRequired

Field in which to find the average value.


projectedFieldstring

Field in the aggregation results containing the average value.

Returns
Return Type:WixDataAggregate
Did this help?