#### Average

##### Average(DBField a)

The function is used to get the average value of the values referred to by the argument.

Parameter

a - Values of DBField or formula field. Can be Number or Currency data type.

Return value

The return value can be Number or Currency.

Examples

- `Number x = Average(@dbfield)`
- `Number x = Average(@formula)`
- `Currency x = Average(@dbfield)`
- `Currency x = Average(@formula)`

##### Average(DBField a, String groupby)

This function is used to get the average value of values referred to by the argument.

Parameters

- a - Values of DBField or formula field. Can be Number or Currency data type.
- groupby - A constant string to indicate the groupby field name or a field variable grouped by or a parameter variable grouped by.

Return value

The result value can be Number or Currency, and is depent on the data type of the first argument respectively.

Examples

- `Number x = Average(@dbfield, @dbfield_groupby)`
- `Number x = Average(@dbfield, @formula_groupby)`
- `Number x = Average(@dbfield, @parameter_groupby)`
- `Currency x = Average(@formula, "group_field")`
- `Currency x = Average(@formula, @formula_groupby)`
- `Currency x = Average(@formula, @parameter_groupby)`

##### Average(Number a[])

This function computes the average of all the values in the array.

Parameter

a - A Number or Currency array.

Return value

The return value is a Number or a Currency.

Examples

- The return value of the following statement is 13.5.

  `Number x = Average([ 11,12,13,14,15,16 ])`

- The return value of the following statement is -13.5.

  `Number x = Average([ -11, -12, -13, -14, -15, -16 ])`

- The return value of the following statement is 11.265.

  `Number x = Average([ 11.25,11.26,11.27,11.28 ])`

- The return value of the following statement is -11.265.

  `Number x = Average([ -11.25, -11.26, -11.27, -11.28 ])`

- The return value of the following statement is 5.75.

  `Currency x = Average([ $5.6, $5.7, $5.8, $5.9 ])`

- The return value of the following statement is -5.75.

  `Currency x = Average([ -$5.6, -$5.7, -$5.8, -$5.9 ])`

Note: If a field is assigned to a variable, for example x, the variable x will lose the characteristic of representing a group of values. The following formula will then be treated as incorrect.

`Number x = @dbfield;
Number y = Average(x); // system will prompt you that there is no such kind of function.`