Help creating complex calculation

Hi everyone,

I’m trying to create a player score that involves a calculation. When I attempt to build the formula using the Expression Builder, it’s not calculating the static (non-dynamic) values correctly. I also tried using the Instant Calculator plugin, but I’m still running into issues.

Here’s the formula I’m working with:

1 + (9 * (Current User’s Games_won / Current User’s Games_Played:formatted as 1028.58) * (1 - (10 / (Current User’s Games_Played:formatted as 1028.58))))

Has anyone encountered a similar issue or know how I can fix this?

Thanks in advance!

What value are you expecting? What are you getting?

Why do you add these :formatted operators mid-calculation?

Thanks for the response!

You’re right, the :formatted parts were added by mistake mid-calculation. I’ve removed those.

The issue is that only (Current User’s Games_won / Current User’s Games_Played) is being calculated. The rest of the expression — like 1 + (9 * (…)) * (1 - (10 / …)) — is just being shown as plain text and not actually computed.

For example, instead of getting the final value like:

3.88 (from 1 + (9 * (0.4) * (1 - (10 / 50))))

I’m getting this as the output:

1 + (9 * (10)) * (1 - (10 / 10))

It’s like the formula is just being displayed rather than evaluated.

Any idea what might be causing this or how I can get the full expression to compute properly?
This is a screen shot of the expression

The numbers you want to calculate seem to be plain text, rather than a valid expression. You will have to always make one expression for one calculation. In there, you will not be able to use parentheses, so the calculation would need to work from left to right. (Except perhaps with the new expression composer in beta which I did not try out.)
One possibility to get the value in parentheses is to store the intermediate values in a hidden Input field that has the calculation in parentheses as default value and then adding it up somewhere else.

You would therefore have:
Input winRate (number): 9*Current User's Games_won/Current User's Games_Played
Input gamesPlayedWeight (number): 10/Current User's Games_Played*-1+1 (btw; shouldn’t that be 1/x, instead of 10/x as it could very well make the factor negative as 10/x can be bigger than 1)
final Result: winRate's value * gamesPlayedWeight's value + 1

You are using manually entered operator (* for example). This need to be selected in the function dropdown. everything should be in blue. Also, formatted as should be in the last (or after) the last parenthesis.

also, you may need to use arbitrary-text:converted to number if you want to start with a number. Bubble have some restrictions on where you can place manually entered number in operation
(for example 1+current user… will not work because Bubble will not accept a manually number at the beginning. You can use Arbitrary-text (1):converted to number + current user… OR you can do Current user + 1 (this will be accepted by Bubble)

I think the best solution for something like this would be using the Toolbox (js2bubble) plugin. It allows you to run JavaScript directly within your Bubble workflows, making it perfect for handling more complex calculations that might be difficult or cumbersome to do with native Bubble functions.

Once set up, you can write your custom JS logic and return the result back into Bubble using bubble_fn_ functions.

1 Like

No reason to use js. This can all be done with Bubble native features.