Tutorial: Total up a repeating group (no plugins required)

Sum up calculations in a repeating group to get a total outside the RG, using custom states.

Setup time: 5 mins. Here’s an example of a shopping cart: Demo and Editor.

Steps:

  1. Add a custom state in the RG for the current sub-total;

  2. Add another custom state in the RG to track the previous value;

  3. Add a custom state outside the RG to hold the grand total;

  4. Set up a workflow when one (or either) of the inputs change:
    – Set the value of the “subtotal” custom state = price * quantity (values in the input boxes)
    – Set the value of the “grand total” custom state = Grand total’s value + Subtotal - Previous Value
    – Set the “previous value” custom state = subtotal

Simple as that! Hope that’s clear - let me know if any questions.

All the best
Rob.

9 Likes

That looks fantastic! Thank you so much! I’m snowed under with something else at the moment but I was excited to check this out and you’ve done it. I’m going to get back into my app soon hopefully and I’ll definitely be incorporating this methodology.
Thanks again. Revel in your greatness!
All the best
Joe

Excellent. Thank you! I’ve spent ages looking at it today and just had to do a minor tweek to the maths in one of the work flows to accommodate a difference in how my RG works.
I’m hugely grateful!!
Thank you again.

1 Like

Hi
I got this to work based on your much appreciated help. Thank you again.
Now, however, in order to save screen space, I’ve made a slight change which has dumbfounded me and sent me back to square one.
Basically, I’ve set my RG to 1 Row and Full List so that if newly selected items are added to it the list grows. This seems to work very differently to your example which has all items in the list.
Is there a way to effectively do the same thing (ie maintain a Grand Total outside of the RG while items are added and quantities are changed?) for a fixed, one row, full RG? This seemingly subtle difference appears to have a massive impact on the workflows and I’ve stuck trying to get it to calculate. I’d appreciate any wisdom on this new twist.
Many many thanks in advance.
Joe

Hi, OMG i’ve been trying to do this for daysssss with no result. I am new to bubble and i still cant rap my head around customs states. Could you please explain this in more detail :pray:

I have a RG that has Input Qty (saved to DB) and Input Price (saved to DB). I also have Input Total in the RG that calculates Input Qty * Input Price :+1:

Now i need to calculate the Subtotal (sum of all Totals) outside of the RG, then i need to calculate the Tax on the Subtotal and finally Add the Subtotal and Tax together.

I’ve been trying to figure out customs states for a while but cant understand them at all. So i’ve been staying away from them but now it looks like i will have to figure them out.

Please help :pray:

@lcsinteriors For subtotals and taxes, I’m using RepeatingGroup Tools to calculate taxes and subtotals. It’s not free, but gets the job done perfectly and quickly.

@robhblake
How would you get that data out of that repeating group and create an order with the total/subtotals? From what I can find, the only solution would be to add a + button to each RG row and then creating cartItems in the database. Then have a place order button that creates the order, adds all those newly created cartItems to the order data type.

Ideally, I’d like to be able to create a custom state that holds the cartItems prior to saving them to the database. A custom state (list of cart items) the cartitem needs to exist on the page before you can add it to the custom state. Is there a way to dynamically create the cartItem and add that to the custom state that can then be passed to the order?

Currently, I’m doing the former, but would really like to be able to do the latter.

Thanks.

1 Like

Hello @robhblake

Thanks for sharing this tip!

I would like to ask how you would save these results as a new list of things. Would you use backend workflows?

Hi @joefarrowsmith! Have you made any progress on this?

Thanks a lot @robhblake!! That worked really well! However i bumped into another problem that i’m trying but can’t figure out how to fix.

How can the grand total show up when the page loads? I have this list of workers already saved and showing in the repeating group, but every time the page is loaded, i have to change at least one input from each line so the grand total shows the right value.

Is there a way to do it using the states?

It’s my first time using bubble so i much appreciate the help!!

Seems that bubble doesnt allow to set custom states from elements inside the Repeating group anymore

Does any know how to resolve this issue??

Very useful demo, and saved me some time in my implementation. Thanks!