4D v18

entitySelection.average( )

Home

 
4D v18
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 null if the entity selection is empty.

An error is returned if:

  • attributePath is a related attribute or does not contain numerical values,
  • attributePath is not found 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 v18)