average of progress (linked items)
Hi there,
I have an app with a relation t oanother app where each item contains a 'progress' (0 - 100 %) field.
When I use the '@Avg of Fortschritt' function, the calulated value is not correct (assuming that the formula should be: value1 + value2 + value3 / numberof items).
What's wrong?
An eror in the calculation function, or am I missing anything?
Any help appreciated!
Stefan
-
Hi Stefan,
if you are on a Podio Plus or higher plan the update to 0 can be done by a flow.
If not you can use another calculation (instead of @AVG of Fortschritt) cause you don't need to update it to 0 in each item:var f = @All of Fortschritt with nulls;
var numberItems = 0;
var sum = 0;
for(var i = 0; i < f.length; i++){
numberItems += 1;
sum += f[i][0] || 0;
};
sum/numberItemsIt's very important to select the variable token "with nulls", not the "normal" token.
Rainer
-
Hi Rainer,
thx a lot for this answer!
Looks really good. Only problem: dosn't work (yet). ;-)
I have an idea of the logic of counting the 'NULL' entries. Whereas to be honest I don't completely get the line:
sum += f[i][0] || 0;
I I get it right, we're running through a field / array of all 'fortschritt' entries. But why only those with NULL?
But isn't a part missing where the items WITH 'fortschritt'-values are added?
Stefan
-
Hi Stefan,
@all of fortschritt returns an array. The elements in this array are the values which are in the field Fortschritt - but only IF there is a value, if there's no value (= null) it isn't in the array (like it is done by @avg of ...). But you want to get the number of all items, with and without values.
@all of fortschritt with nulls returns all items.
You can test that.
enter
@all of fortschritt. length - the result is a number
then enter
@all of fortschritt with nulls.length - the result is a higher number if there are items related where Fortschritt is null.
I assume the result of sum is 0 - right? Change it to sum += Number(f[i][0]) || 0;
|| 0 means: If there is no value replace it by 0.
A short alternate for my previous code is:@sum of Fortschritt / @All of Fortschritt with nulls.length
(Sometimes I think to complicated :) )
Rainer
Please sign in to leave a comment.
Comments
5 comments