Apply formula to dynamic data

Hi all,

I have a problem that should be pretty simple. I need to display:
CURRENT ITEM’s THING formatted as currency “Per month”
(CURRENT ITEM’s THING formatted as currency “Per week”)

where the second item is the first divided by 4.

How do I apply simple formulas to dynamic data? I may later want to apply discounts and other transformations to results, so this will be helpful.

Current Item's Thing/4

Hi, thanks. There was a bit of moving things around but made it work.

Any ideas on how we could save a formula which would need to use dynamic data?

I’m using a plugin that allows for the creation of a formula, which works well, and that formula is saved to the database as text and when running that text with the plugin it calculates correctly.

But, where I’m stuck at the moment is thinking of a way to let a user construct the formula with some dynamic data in mind (ie: response to a question like ‘what is the width of the room’) where the value for width of room is not able to be stored into the database.

What on earth are you talking about @boston85719? “A plugin that allows the creation of a formula” makes no sense. What is it you are doing/trying to do? You’re a smart guy and I’m worried you’re on the fentanyl or the TikTok (I have heard that both of these are bad).

Don’t overestimate me :laughing:

I am currently using a plugin that allows a formula to be evaluated, so it doesn’t create the formula, it simply will calculate it.

It works very well how I have tested it, which is to have a user input via an input or multiline input element the formula they want to calculate.

After the user inputs the formula I save it to the database as text and it can be used in the plugin element and evaluates fine.

What I am trying to do is figure a way that a user could create a formula that has an unknown dynamic value. It is for a chatbot, and based on a users answer the formula will need to calculate.

In this case it may be that a chatbot asks what is the room width and there would be a formula saved that would utilize the room width, but that saved formula would need to be able to utilize the dynamic data, in this case the users answer to the question what is the room width.

In past I have done things for document creation that I let a user add a value like {user’s_name} to the document and then I find and extract that value with the input’s value.

I’m think that I would need to do the same thing here for the formula to be dynamic and saved to the database.

Oh, so some sort of expression parser? I gotta say, the easiest way to do that is through a plugin. Like, in Polyhedra, you can enter “natural language” type expressions for dice rolls, e.g., “2 D 20 + 5d6 - 7” and get the result of the roll. How this is done is via a combination of regex and native JS features, though you could do that in vanilla bubble depending upon your pain tolerance.

Wasn’t aware of a generic bubble plugin for that, but that’s interesting.

But the concept is really simple. For example in Polyhedra I strip the white space from the string, conform all d’s to lowercase d’s and then split the string at the +/- signs and go from there.

It sounds to me like you’re treading in custom code territory that — in fact — is much easier than dong things in vanilla bubble, so maybe time to go the easy route and uplevel.

1 Like

Thanks for that. It helps me contemplate how this will function with the values provided by the user in the chat.