average of progress (linked items)

Comments

5 comments

  • Stefan Myoshin Schoch

    Found the reason myself.

    When an item is created, the progress field is not '0' but empty. So I have to make sure all not yet begun items have the progress value of '0'

    0
    Comment actions Permalink
  • Rainer Grabowski

    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/numberItems

    It's very important to select the variable token "with nulls", not the "normal" token. 

    Rainer

    0
    Comment actions Permalink
  • Stefan Myoshin Schoch

    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

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    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

    0
    Comment actions Permalink
  • Stefan Myoshin Schoch

    That works great!

    And it makes even more sense to me… ;-)

     

    Thx!!!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk