Forum Academy Marketplace Showcase Pricing Features

Calculations with parentheses

Hi guys,

I was wondering if you had a solution, or a workaround for what I am trying to do.
Let’s say I pull numbers a, b and c from my database.

When I display a number made of a, b and c I can do a * b +c, I can do (a+b)/c via a/c + b/c
but I have no way of doing a/(b+c), which I need to compute ROI (net profit over total investment).

I’d appreciate any lead!

One options is to use custom states as intermediate steps.

You could also potentially use the new plugin that allows you to do expressions. Toolbox plugin - collection of utility elements, although I haven’t used it, so can’t say for sure!

Hi Adrien, Take a look at the Calculate BMI example here – https://bubble.io/documentation – it shows how to use the http://api.mathjs.org API. I used it in one of my apps and it worked as expected.

Thanks guys!
I tried to the toolbox but I have trouble making it work in Repeating Groups with the Current cell’s thing.
I am going to look into custom states, as I am not too familiar with them yet.
If everything else fails I’ll look into @jnbridges’ solution, but I would rather not use an external API if I can.

HI @adrien checkout the Toolbox plugin that was just released about a day ago. As a new bubbler it has just saved me a lot of dirty workarounds.

Using an API is appropriate if for example, you have an API workflow executing on the server and don’t have a browser page to run the elements.

What trouble did you have?

I think I manage to replicate my issue in a test app.

I am using the Expression module of the Toolbox in a repeating group. I have two Data Types. And each time has a key field. And using the expression I do, Thing 1’s Value + Thing 2’s Value, as you can see the third row doesn’t display.

Also, another little issue that I think I found is Expression B doesn’t display, when there is no calculation.

The reason it doesn’t display, is that it is being asked to evaluate this expression:
"1+ "

The search results in an empty list, which is represented in the expression text as blank. It does produce an error on the browser console.

What you probably want in this example, is to treat an empty search result list as a zero value in the expression, which you can do with:
Search for Test thing2'sValue:max

Be aware that treating a returning list as a single number can have unforeseen effects, like if there are duplicate or missing keys in the table.

The checkbox “Data has no executable code” was unchecked for Expression B.

I’ve added the above suggestions to your example.

Thank you @mishav for your help and your guidance.
In my app, I am already using :sum so I wasn’t able to use :max, but by using :floor it resolved the issue.

Thank you so much! The toolbox is a lifesaver for me!