Command AVERAGE Foundation

Calculates the average for numeric expressions in the current work area.

Syntax
AVERAGE  <nExpression,...> TO <VarName,...> ;
  [FOR   <lForCondition>] ;
  [WHILE <lWhileCondition>] ;
  [NEXT  <nCount>] ;
  [REST] ;
  [ALL]
Parameters
<nExpression,...>
<nExpression,...> is a comma-separated list of numeric expressions evaluated for each record. The return values for each record are used to calculate the averages.
<VarName,...>
<VarName,...> is a comma-separated list of variables containing the sum of each numeric expression from the list <nExpression,...>during the determination of averages. After completion of the command AVERAGE, these variables give the average for all records used in the calculation. The variable list <VarName,...> must be exactly as long as the expression list <nExpression,...>.
<lForCondition>
<lForCondition> is an optional logical expression which defines a condition. Only records for which <lForCondition> returns the value .T. (true) are considered in the average calculation.
<lWhileCondition>
<lWhileCondition> is an optional logical expression which defines a condition. The calculation of averages is terminated as soon the expression returns the value .F. (false).
<nCount>
<nCount> optionally specifies the number of records used in calculating the averages starting with the current record.
REST
The option REST specifies that the average is to be calculated only for the records starting at the current record and continuing to the last record. If a condition is specified, the option ALL is used as the default value.
ALL
The option ALL specifies that all records are included in calculating the averages. If a condition is specified, the condition is tested for all records.
Description

The command AVERAGE calculates the average of one or more numeric expressions based on the values of the records in the current work area. Specifying a condition or the number of records limits the records used in calculating the averages. The command sums the numeric expressions and divides the result at the end by the number of records included. The average of each numeric expression in <nExpression,...> is assigned to a variable in the list <VarName,...>.

Examples
AVERAGE
// In the example, the average daily sales for the 
// month of June are calculated. 

PROCEDURE Main 
   LOCAL nIncomeJune 

   USE Invoice NEW 

   AVERAGE Payment TO nIncomeJune ; 
       FOR Month(InvDate) == 6 

   ? "Average daily sales in June:", nIncomeJune 

   USE 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.