# Basic calculation help required

I’ve spent literally months learning Bubble and creating an app which I was really pleased with. Until today. I just want a basic, fundamental calculation but It seems that Bubble simply doesn’t have functionality that enables someone as apparently thick as me to do it.

I’m trying to create a kind of order preview screen so that a User can see how much they’re spending before progressing to a payment page.

All I want to do is sum up an input in a repeating group that contains Totals that I’ve calculated by using a simply formula (InputQty * InputPrice) that someone helped me with here last night and for which I’m truly grateful.

I now need it to display one single Grand Total figure so it has to go outside the RG but this seems to require multiple complex, advanced workflows and custom states. I’ve now spent 5 hours watching videos and reading the manual to try and find out how to do this. Other people have asked for this but these posts just lead me down some kind of superadvanced rabbit hole.
Surely there’s a way in Bubble to just use a Sum function on an input box?
I know I’m new to Bubble but really, this seems so fundamental to any app that I can only have missed something. I’m completely aware that this could be user error as I can’t even find any documentation in the manual or via google on SUMPRODUCT - maybe that’s how it’s done though.

I’d be so grateful if someone can show me how this is done or just tell me it can’t be done so I can cut my losses and walk away and learn some other platform.

I’m a newbie here so I apologize in advance if you’ve already tried this way: I think you should able to do the math in the database. And then you’ll be able to request and display the value.

Thanks for your reply. Could you expand on what you mean by “Doing the math in the database”?

The problem is to show the total when you load the data in the first place or to show it changing while you change the amount of each item in the RG?

Or both ?

It’s to show it changing while you change the amount of each item.

Although I can’t even find a way of doing the calculation…

Really appreciate any help. I’m just mocking up a simple example that I can link to here. Will hopefully be back with it very soon.

Honestly the simplest way I’ve found is to use a plugin and I can suggest the “Repeating Group Tools” by BDK. This lets you send data from an RG cell to a “receiver” outside the RG then you can run your totals

This do not involve interacting with the database, so it’s quicker.

That’s the hack-free way of doing it. I’m experimenting with some native hacky options but nothing to report yet.

Cheers,
Rob.

That sounds excellent. Thank you. I’ll look into both of those - I’m in awe of you creating one yourself.

Thanks again.

1 Like

@joefarrowsmith hey I just created this. Enter numbers in Input 1 and Input 2 and it displays the multiplication right next to it. Is this something you’re looking for? - https://mafiamap.bubbleapps.io/version-test/calculation?debug_mode=true

I guess there’s more to it because of the currency format?

@bestbubbledev He needs to extract the total from a repeating group.

@joefarrowsmith perhaps hold off using the Communicator plugin - I’ll put a demo together this eve to make sure it solves your use case before you sub/purchase.

And why he needs a plugin to do it? It is not easyer to trigger a workflow everytime his input field changes? So everytime his input field changes, Bubble update his database.

And he will only need a “total” field “Searching for” the SUM of the products showned…

I am not seeing much complexicity here

1 Like

Good point I had mixed up the facts: you can access workflows from within the RG, but you can’t access RG elements from outside the RG (that’s what the plugin solves). My bad - I’ve removed that suggestion.

RE the “seach for” solution, I’m not a fan since he will also need a way of tracking the users’ shopping cart not just the items in it… Also interacting with the DB will slow down the UX a small bit.

@joefarrowsmith I’d recommend BDK’s plugin if you’re going the non-DB route.

Thanks very much. I’m just on a call getting distracted by something else but I think Giorgi is onto something there. That works nicely. I am indeed trying to apply it to a repeating group and I’m mystified as to why I can’t. I feel I’ve missed something fundamental. I’ll be back when I’m off this call but I do appreciate the help here.

This looks like what I’m trying to do. Any chance you can do a screen dump of the design to see how you achieved that? I don’t think the currency format should be causing there to be more to it. Thank you for this…

Folks, I’m going to have to run for today but I do appreciate everyone’s help with this. It’s been driving me nuts! I actually think I need to make a few db design changes to my data.
I’ll be back on tomorrow (I’m UK based) - just didn’t want anyone in a different timezone thinking I’m not interested by not replying straightaway to further input.
Thanks again.

@joefarrowsmith I’m not doing anything special but you got it.

1 Like

@joefarrowsmith

My apologies to all that I have not read the entire thread in detail, but I did scan through it.

Perhaps something along these lines could help a bit. Notwithstanding the current UI, current flows and current dB structure and exact names of the objects … the following aims to be somewhat of a reference:

Order
Title (text)
Total dollar amount (number)
Line items (list of line items)

Product
Name (text)
Price (number)

Line item
Product (product)
Quantity (number)
Order (order)
Dollar amount (number)

• Create an order
• Create the line items assigning product and order
• Add each line item as it is created to the order’s list of line items
• In the rg of line items (let’s call it rg A) the user inserts the quantity in an input of type number and a flow (trigger when input value changes) calculates the line item amount
• Below the rg in a group’s of type number populate its data source with an expression “rg A’s list of line items amount :sum” and use this group to load the total amount to the order’s total amount field.

Hope this sparks some ideas

1 Like

This is amazing. Thank you so much, I’m in awe of the help here.

I think what I’m going to have to do is edit my database structure which I’d been trying to avoid but, actually, it’s causing me problems. One of my issues is that the input I’m using to take the Qty is simply a “standalone” input, not linked to any DB field. I was hoping I’d be able to have the user “preview” what they’re about to spend and, so long as they’re happy with that, have all the products and quantities taken from those inputs and recorded in the db.

It’s clear to me now that I’d be far better off basing this screen on a live “Order” input which can then perform the calculation because, as it stands, there’s no option to pull my standalone input box into the expression builder but I’ll be able to do it with data type fields.

If it weren’t for the kindness and generosity of you guys on here, I wouldn’t have come this far and while I’m not looking at Grand Totals right this minute, I’m much more confident that I know what to do now to achieve it because all the responses certainly sparked ideas. I also have a good understanding of Custom States, calculations, workflows etc - dropping yourself in it like I did is frustrating to others but the learning curve to get out of it is very valuable and only made possible by you guys. Thank you.

Giorgio,
Many thanks for this. Your generosity with your time and patience to explain this is humbling! I’ve worked out that I need to make some fundamental design changes to my Db to get it to work but your video here has really, really helped me understand calculations etc and my confidence with Bubble has grown. Many, many thanks.
Joe

Definitely some ideas sparked. I’ve marked this as the solution because I now understand that I need to make some fundamental changes and then this response will be the bedrock of my way ahead.
Many thanks.
Have a great weekend

2 Likes