Forum Discussion

evaldobaladelli's avatar
evaldobaladelli
Copper Contributor
May 07, 2020

Como calcular a média aritimética entre varios itens (registros) de uma mesma coluna no SharePoint?

Como eu posso obter o resultado do cálculo da média aritimética entre varios itens (linha de registro) de uma lista para a mesma coluna no SharePoint?

Exemplo:

Lista: Exemplo

Nome Col1 (Valor)       Col2 - (Média Aritimética dos valores da coluna 1)

Jhon    10                     10

Peter   20                     ((10 + 20)/2) = 15

Max    20                     (10 + 20 + 30)/3) = 20

.          .                          .

.          .                          .

.          .                          .

 

 

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    evaldobaladelli I don't know of  a way to do this in SharePoint as it can't loop through the items in the list. So you either need to do something in Power Apps or build a flow in Power Automate which is what we're going to do here to get the items in your SharePoint list, loop through each one, do a calculation and save the median value of each item back in the SharePoint list.

     

    The list in SharePoint:


     

    In Power Automate the flow starts with a Recurrence schedule trigger. I've set it to run every 1 day but you could do it as frequently as necessary. Or perhaps use a SharePoint When an item is created trigger. Next, add 2 Initialize variable controls and make them both Float type. 1 is to store the row count and one is to store the total score.

     

     

    Next add a SharePoint Get items action, select your site and list and I've set the order to ID:

     

     

    Add an apply to each control and select value from the dynamic content. Inside the apply to each add 2 Increment variable controls the row count one to 1 and the total variable to the score, selected from the dynamic content box:.

     

     

    Next add a Compose control and in this you will add an expression:
    div(variables('varTotal'),variables('varCount'))

    which will divide the current total by the current row count:

     

     

    The final step is to update the SharePoint list item with the output of the Compose control.

     

     

    This is the result:

     

     

    Rob
    Los Gallardos

    Microsoft Power Automate Community Super User

Resources