Data Source Math

Hi. My partner and I are creating an app that allows you to input activities with duration, and it takes that information, puts it into a data table, and calculates the stress level after clicking a button. Basically, we need to figure out how to take the numbers from the data table and add them together, to then divide them by 24. We have tried TONS of different pieces of code, to find out they don’t work. The closest we got, was by using the “list of values” block. (Picture included). However, that block only used the math on the first added event. Can we have some assistance? I included a picture of the project and the list of values blocks. Thanks!

image

1 Like

The “list of values” block creates a list like {3,4,9,15}. You can’t add those together. Instead, replace each one with a “get value from” block from the Data Sources drawer.

Please give an example of the values you’re wanting to add together because it’s not clear from your post.

If you’re adding a whole bunch of numbers together, you can either use a whole bunch of + blocks from the Math drawer or you can loop through the “list of values” and add each iteration of the loop to a variable. That’s what I would do.

1 Like

So basically, the user writes a number in a text input, it then creates a value in the data source which is what the number added is. What we need is, to have all numbers in the data table add up, and divide by 24.

@tatiang

1 Like

You should do it in a way similar to this

image

This is the content of the table
image

This is the output
image

2 Likes

Thank you!!! I will try it out later

2 Likes

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