How to Sum (Price * Quantity) for Each Item in a Custom State List?

Hey everyone,

I’m running into an issue with calculating a total sum in Bubble and could really use some help.

I have a list of items stored in a custom state.

Each item has a price and a quantity.

The list is displayed in a repeating group. Outside the repeating group, I have a text element that needs to show the total sum of (Price * Quantity) for all items.

I want the text element to display the result of:

(Price1×Quantity1) + (Price2×Quantity2) + (Price3×Quantity3) +…

However, I cannot find a way to correctly structure this expression in Bubble. What is the best way to achieve this?

i use the instant calculator plugin, works perfectly

1 Like

thanks for your answer but i really want to avoid the use of plugins for my app

is the quantity for each item in the rg saved in the db?

1 Like

the items are saved in the database. every item has a ‘price’ field and ‘quanity’ field

i just want the text element on the page to have the value:

→ each items’price * each item’s quantity : sum

okay so the quantity of the item eg the user selects this product 20 times the 20 is saved to the db? Or does the user have 20 times that item?

1 Like

if the user selects the item 20 times, the item is saved just one time with a quantity of 20. so the 20 is saved in the database. the item does not appear 20 times in de database. Not sure if that’s the correct answer to your question?

i would just save the :sum of the price for each line in the db so you have acces at all time to the sum of that exact line items sum and wouldnt hurt so when creating or making changes just include the sum as an extra field so you can later just say rgs each items Product, linePrice_sum, :sum

1 Like

I really appreciate your help, but that’s exactly what I want to avoid. I don’t want to create an extra field in the database for the subtotal because I want to reduce workloads.

1 Like

and custom_state_name:each item’s price * quantity:sum doesnt work?

this should work, you can even save on the set state of an element action :DD

1 Like

thanks for the effort, really appreciates it ,but i dont know what you did tbh. is that a plugin?

just search for calculate formula in the dynamic options you are beeing provided with, then select calc sum product from the dropdown

(its on the very bottom, if you want to scroll down)

1 Like

a bit of a late responsee but thank you ver much! this works. legend.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.