Forum Documentation Showcase Pricing Learn more

Simple calculation question


HI everybody,

So how do you perform simple calculatino which go beyond inpu1+inpu2+input3?
Input1*(search table for value)/ ( Input1*(search table for value))+(Input2*(search table for value))*100?

Right now I simply use some custom states, but it might be even easier then that.


Well, because there are some limits to how fancy you can get in the expression editor (and there’s no parentheses, and expression evaluation works purely left to right), it’s often easiest to just do the computation in multiple workflow steps (as you’re doing) rather than struggling with rewriting your math to work the Bubble way.

There’s very little performance difference in most cases, anyway (as long as you’re kerping your intermediate values in the page — I.e., in custom states — rather than pushing them back up to the database).


@SenorPelota Out of the simpler built-in calculations, ‘calculate formula’ > ‘calculate sumproduct’ is pretty nifty for carts and other financial calculations.


You can try to use the math.js plugin. That would allow you to do some complex calculations.


Thanks all for the suggestions. @paritosh.mehta19 that is a really good option, I rejected the plugin way a bit because of adding a potentital other API call for such a straight forward ( relative) simple calculation. This one is local, I am defenitely going to check it out. @keith For the moment I’m staying with the custom state option for the calculations. Not fancy, but it does what it is supposed to do. Sometimes hearing the chosen method is the right one is almost as handy as hearing a new method ;)…

@Neerja. Still waiting for the first usecase where I need to add lists together, but I presume I will be adding charts not for to long. Thanks for the tip!

P.S: Nobody picked up on my incidental super funny typo ( Calculatino). Caramba!


That would be a great name for a “Mathletics” team, for sure.


But on a serious note: Basically, when you write a multi-step workflow that’s operating entirely locally to do a computation, it’s basically exactly like writing a very deliberate (easy to understand), but not highly optimized multiline JavaScript, like:

var a = something
var b = something_else
a = a^2
b = b^2
var c = a+b
c = c^0.5
return c

(The above being a very long-winded and funny way of solving the Pythagorean theorem.)

Sure, you could write:

return (something^2 + something_else^2)^0.5

… but is there really any measurable performance difference? Not unless you’re iterating that a LOT of times.

And since — in Bubble — iteration is more or less prohibited, it’s just kind of not a big deal.

Edit: though I would probably silently judge the author of those 6 Element > Set State steps (that would be the Bubble equivalent) as something of a goofball.