This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
entitySelection.average( )
|
entitySelection.average ( attributePath ) -> Result | ||||||||
Parameter | Type | Description | ||||||
attributePath | Text |
![]() |
Attribute path to be used for calculation | |||||
Result | Real, Undefined |
![]() |
Arithmetic mean (average) of entity attribute values | |||||
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:
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)
Product: 4D
Theme: ORDA - EntitySelection
Created: 4D v17
Modified: 4D v18 R6
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)