[Solved] Calculate the average from the list

I need to calculate the average from this list. everything works, but the variable is overwriting and I have to turn the applications off and on for the calculations to be correct. What can I do with this?

We can’t help you without seeing a screenshot of your blocks or a link to your project.

Check out this recent post from Thunker @David_Wolber

Aha… sorry :wink:

1 Like

Okay, well that function will add each list item to create a sum, not an average. If you want an average, then you need to do set app variable total to app variable total + j (or just change app variable total by j, which does the same thing) and then below the loop, set app variable average to app variable total/length [list of values in payments history in Table 1 in price].

If you have the data in Google Sheets or Airtable already, you can just use a formula to get the average. But if the data is in a local data source, you’ll need a function like you’re using.

You can average a list. Would this help?

2 Likes

after all these years, i never noticed that you could do sum, average, etc and other list-related functions with ready-made blocks!!! i always had to write a sum function everytime i needed one! (i was looking for sum in the math blocks but there was none)

image

1 Like

below I have unpinned blocks that define the length of the list and divide the sum by these blocks. my blocks calculate the mean but overlap in the variable. I have to turn off and turn on the Application for the result to be correct. every time i use the “average” function everything is x2 and so every time the function restarts. only resetting the app helps. I don’t know how to stop it.

Sometimes it is a good idea to have your own functions.
Try the sum or average on the block like this
image
You will see that it does not work and you will revert to building your own function. Lists generated from Data Sources default to text and therefore the calculation functions do not work with them.

1 Like

here all the blocks. the function works, but the computations overlap each time I want to use it. If that’s not possible, how else can I build such a function?

1 Like

Inside your average function, the first block should be set app variable average to 0. This will ensure that the average is not being added up every time.

1 Like

Omg… THX

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.