Adding numbers and displaying total

Is there a way to add the numbers a user inputs and then display the total? Let’s say a user inputs 50 pushups, for today, and for tomorrow, inputs 30. How can I add those values in order to display them in a ‘weekly total’ textbox? Or are we limited to increments of 1? Thanks.

Well, there are a few ways to tackle this. If you’re not wanting to save the individual days and just save a total number, when the user adds a new input you’d Make a Change to Thing > Pushups = This Thing’s Pushups + Input Value

If you’re recording each day, then I’m assuming you’re creating a new Day for the user every day so that every day’s values are stored. You can use dynamic text in a text box to search for the values in a date range that you want and use the :sum modifier to add them. Ex: Search for Days’ (with date range constraints) Pushups:sum - this method just adds values to display without saving the total to the database.

You’re definitely not limited to any increment. You can use the “+” modifier in your workflow before any static or dynamic value (in your case, pulled from an input on the page)

Does this help?


Gaby | Coaching Bubble

9 Likes

Sort of. I say that because i’m looking at the workflow and don’t see where I would input - ‘Pushups = This Thing’s Pushups + Input Value’- in the Make a change to thing. I have the number value set to #. Fyi. here is the link. https://bubble.io/page?type=page&name=huh&id=calendar-app-trial&tab=tabs-1

Ok, so the way you have it set up is my scenario 2. Check out the text box I added to display your total. It’s a search of all logs and then summing up the # field.

1 Like

Thanks. I truly appreciate that. I would have never figured that out. I was under the impression that the changes had to be made in the workflow in the data(things) selection.

No problem! Yeah, if you wanted to save that total to the database, you’d do that in the workflow so that it saves to a dedicated “total” field under an appropriate data type. In your case, the user type would make more sense since your only other type is meant for individual days.

Using dynamic text like that allows you to format your existing data in a variety of ways without necessarily needing to save.

geeze i’m lost here. Lol. First, how did you get the sum to appear as a total. I mimicked what you did but I got all the separate data entries for #.

You’re good… you’ve entered “:sum” as plain text. You can tell because it’s white. Delete that, and then click on # to reveal a prompt that says “more” … click on More and it will reveal all your available modifiers, including :sum. You’ll see that it is now blue because it’s a dynamic value.

oh ok. Instead of clicking on more I kept clicking on the blue ‘insert dynamic data’ tab. Lol. Thanks a lot for the help.

what would be the difference of saving the values in the database as opposed to doing it this way? is there a real benefit to doing it one way over the other? thanks.

Well, I guess it all just depends on what you want to do. If the total values are something you want to use in a lot of places, it might be easier to just save them so that your dynamic text is just “Thing’s Total” - say you wanted to then take that number and use it in some way. Like if the user has a weekly goal, you could compare the total to the goal as opposed to doing that :sum again to calculate a total.

It really depends. We could have saved the total, and your result would have been the same. I think at this point the question is more about what you want to do with all the information from here.

Got’cha! Thanks for all of your help.

1 Like

Ok looking at the link, I included the bar chart. What I want to do is save the pushup’s total and display the total on the chart on a weekly basis. I tried to do it but there seems to be no way of accomplishing this using the ‘search for #:sum’ that you showed me. Would it work by saving into the database and pulling out the total? Thanks.

Hey, I’m on mobile only this weekend, but I’ll do my best to describe an approach until I can access your editor tomorrow…

To store and display a weekly total like this, I wonder if it’s better to restructure your log structure. Instead of a log for each day, have a log for each week with 7 # fields for each day. Then have a total field (type number as well).

When a new day is recorded, you would Make a Change to the log:

Day (the new one) = input value
Total = this log’s total + input value

When the week is full, you can create a new week. The chart would then be able to use the Total values from every log created by the current user.

Let me know if this helps. I’ll need to look at your editor to come at it a different way if you want to keep your log structure the same, which I can do tomorrow.


Gaby | Coaching Bubble

Thanks for that. I still have to work on that approach.

I’ve been messing around with the info you provided several days ago and it’s starting to register with me. I was able to take it and create two inputs ‘A’ - ‘B’ = ‘Do a search for…’ and it works well thanks to you.

Now, what i’m trying to do is create a condition that when the sum of both values is (-), then the total displays 0. Which I did. I also want, once the total <= 0, any previous input to be deleted. Because if you go into the link you will see that it reaches zero but once a new number is entered it also gets calculated with the invisible (-) total.

Thanks for this! This solved a big problem for me. Is it possible to have this :sum text data update without having to refresh the page? The chart and graph element does not require a page refresh to update the data, I’m wondering if I can have text operate the same. Right now I see it requires a refresh.

Gaby, you’re incredible! I was stuck on this for a week, read different posts, but I wasn’t asking the right way, finally found this post and “SUM” worked like magic.

Didn’t even know “SUM” existed in bubble. You’re a life saver, thank you for taking the time to help the community.