4D v19

entitySelection.average( )

Home

 
4D v19
entitySelection.average( )

entitySelection.average( )  


 

The entitySelection.average( ) method returns the arithmetic mean (average) of all the non-null values of attributePath in the entity selection.

Pass in the attributePath parameter the attribute path to evaluate.

Only numerical values are taken into account for the calculation. Note however that, if the attributePath of the entity selection contains mixed value types, entitySelection.average( ) takes all scalar elements into account to calculate the average value. 

Note: Date values are converted to numerical values (seconds) and used to calculate the average.

entitySelection.average( ) returns undefined if the entity selection is empty or attributePath does not contain numerical values.

An error is returned if:

  • attributePath is a related attribute,
  • attributePath designates an attribute that does not exist in the entity selection dataclass.

Example  

We want to obtain a list of employees whose salary is higher than the average salary:

 C_REAL($averageSalary)
 C_OBJECT($moreThanAv)
 $averageSalary:=ds.Employee.all().average("salary")
 $moreThanAv:=ds.Employee.query("salary > :1";$averageSalary)



See also 

entitySelection.count( )

 
PROPERTIES 

Product: 4D
Theme: ORDA - EntitySelection

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)