
Exclude blank values from average calculation
Hi there,
I have a question about the use of the avg([array]) function, or I would like to have an alternative to calculate the correct average value (mean) in my situation.
Situation
I have a model with a couple of properties which are all 'number with decimal'. I want to calculate de average value (mean) of all the properties that have a value.
When a property is blank it should not be part of this calculation. When the value is 0 (zero) it should be part of the calculation.
I deliberately designed my model this way, because a want to present all these values in a single editable form in the back-office.
When I use the avg([array]) expression, blank values are still part of the calculation.
For example: the expression avg([1,0,3]) has an average of 1.33 (4/3). The expression avg([1,'blank value',3]) also has an average of 1.33 (4/3). But for my purpose it should have calculated an average of 2 (4/2).
Workaround
As a workaround I've created an action in which I created variables that enable me to calculate the average value the way I want:
numerator:
sum([ var:record.a1
,var:record.a2
,var:record.a3
])
denominator:
sum([
(blank?(var:record.a1) ? 0 : 1)
,(blank?(var:record.a2) ? 0 : 1)
,(blank?(var:record.a3) ? 0 : 1)
])
In this case the average (in the second case from my example) is calculated with the formula 4/2.
Although my workaround is working, it is not efficient en when more properties are involved the more time it takes to (re)calculate the average value.
Question:
Is there another more efficient way to get the average values I want?
Hi there,
I have a question about the use of the avg([array]) function, or I would like to have an alternative to calculate the correct average value (mean) in my situation.
Situation
I have a model with a couple of properties which are all 'number with decimal'. I want to calculate de average value (mean) of all the properties that have a value.
When a property is blank it should not be part of this calculation. When the value is 0 (zero) it should be part of the calculation.
I deliberately designed my model this way, because a want to present all these values in a single editable form in the back-office.
When I use the avg([array]) expression, blank values are still part of the calculation.
For example: the expression avg([1,0,3]) has an average of 1.33 (4/3). The expression avg([1,'blank value',3]) also has an average of 1.33 (4/3). But for my purpose it should have calculated an average of 2 (4/2).
Workaround
As a workaround I've created an action in which I created variables that enable me to calculate the average value the way I want:
numerator:
sum([ var:record.a1
,var:record.a2
,var:record.a3
])
denominator:
sum([
(blank?(var:record.a1) ? 0 : 1)
,(blank?(var:record.a2) ? 0 : 1)
,(blank?(var:record.a3) ? 0 : 1)
])
In this case the average (in the second case from my example) is calculated with the formula 4/2.
Although my workaround is working, it is not efficient en when more properties are involved the more time it takes to (re)calculate the average value.
Question:
Is there another more efficient way to get the average values I want?
Login to reply