# How do you do this calculation in bubble?

I’m trying to reduce a list of prices by 5%.

So I do: Make Changes to a list of things --> the thing --> price = price - (price * 0.05)

But the problem is, there’s no way to instruct bubble that I need to get the 5% first before it starts minusing. It returns the value as 0, since N-N0.05 is different from N- N0.05

Using custom values to calculate the 5% first and then referencing it is not possible since I have to do it for a list of things. So the action must be done within the same “make changes to a list of things” box.

There might be another way. But I’m thinking you could load the list. Work on it in a state. Then save it back to the database? I haven’t needed to work on lists like this before, but that’s all i can think of right now. Might be slow on big lists though. I’m sure someone else has better ideas however.

@abhi bubble doesn’t follow order of operations, it calculates as you go, so it’s doing (price - price) * 0.05. the better way to do your calculation is price = price * 0.95.

Is there a reason why it has to be 0.95?

Does multiplying the price by this number gives you 5% of the value everytime?

if you wanted to reduce the price by 0.05 (or 5%), that’s the same as multiplying it by 0.95 (or 95%).

price - (price * 0.05) = (price * 1.00) - (price * 0.05) = price * (1.00 - 0.05) = price * 0.95

yes, makes sense. I could have this as a workaround for now. Thanks

That being said, is there no solution to have bubble work in a proper order of operation? Maybe adding a parenthesis on each operation to identify them?

Could be a useful feature to add imo as it is very useful in multiple calculations.

@abhi

This video speaks to exactly your question

If you are unable to perform API workflows because of being on a hobby plan, then an alternative way would be to utilize custom states and set up things in such as way that different custom states represent different operations in the calculation.

Custom Sate 1 = percent change ( 0.05)
Custom state 2 = percent as a price ( custom state 1 * price )…if you are not familiar this would be what 5% of the price of the product is equal to
Custom state 3 = New Price ( original price - custom state 2 )

Breaking down the order of operations with some strategic planning allows you to do any complex calculations you may normally require an order of operations to be followed.

Hi all - We recently released an experimental features UI that has a development version of parentheses. Learn more here! Hope you all have the opportunity to start playing around with it and help us iterate to make it better!