#### Average

Function

- Average(array_variable);
- Average(field_variable);
- Average(field_variable, groupby);

Description

This function is used to return the average value of a group of values referred to by the first argument. The second argument, if there is one, returns the group by field name.

Arguments

- field_variable
  field_variable is a special variable in Formula. It refers to a group of values of a database field or of a formula field. Whatever source they come from, database or formula, they should be of Number or Currency data type.
- array_variable
  array_variable refers to an array whose element is of the Number or Currency value.
- groupby
  groupby can be a constant String which indicates the groupby field name or a field variable on which grouping occurs, or a parameter variable that can accept a different value before each execution of a report.

Return type

The result type relies on the first argument. It can be of the Number or Currency data type, if the data type of each element in the first argument is also of the Number or Currency data type respectively.

Examples

- `Number x = Average([1.0, 2.0, 3.0, 4.5, 45.0, 67.0])`
- `Number x[6] = [1.0, 2.0, 3.0, 4.5, 45.0, 67.0]; Number y = Average(x)`
- `Currency x = Average([$1, $2, $3.0, $4.5, $45, $67])`
- `Currency x[] = [$1, $2, $3.0, $4.5, $45, $67]; Currency y = Average(x)`
- `Number x = Average(@dbfield)`
- `Number x = Average(@formula)`
- `Number x = Average(@dbfield, "group_field")`
- `Number x = Average(@dbfield, @"group_field")`
- `Number x = Average(@dbfield, @parameter)`
- `Currency x = Average(@dbfield)`
- `Currency x = Average(@formula)`
- `Currency x = Average(@formula, "group_field")`
- `Currency x = Average(@formula, @"group_field")`
- `Currency x = Average(@formula, @parameter)`

Note: If a field_variable 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.`