Converting text to numbers to add up

I have a dropdown input with 5 text values (ie. Basketball) that are then saved. Each text value corresponds to one number value (ie. 2000).

How can I convert these text values to numbers, and then add them up to display on the front end (ie. Basketball + Baseball becomes 2,000+3,000=5000 on the front end)

Any guidance would be much appreciated.

Create option sets for these values and add the numerical value as attributes. This is the easiest way.

This is the option set with the extra added attribute:

And you can edit each option set value to update the value attribute:
chrome_yXW1ZuUbNg

And you can display the Display value in the dropdown and when you will calculate, you will get the Value attribute of the selected option sets.

1 Like

Thanks, but I’m trying to see if I can do it without option sets, just on the front end where the text is displayed, because otherwise I’ll have to rework quite a bit of my backend on my line site

I see. Even in that case, you can still create the option set to get the number values of the texts (“basketball” for example) in one central place to add them up. Simply, you will use the option set not to update your front end, but just to get the number equivalent of the text.

1 Like

agreed. You could do this with Arbitrary text but then you have to make many conditions, it’s more work than just using the option set.

Okay, but I’m confused with how I would link the option sets with the text values in the dropdown?

Hm okay, thanks. But do switch to option sets it seems like I’ll have to redo a lot in the back end that currently is set up to deal with text not OS. So in that light arbirtrary text for this one small feature seems better, but I dont know where to start

I guess you are right. I have tried and option sets couldn’t easily handle this scenario. [It handles, see the message above]

I could do it with a custom data type though. See the demo below:
chrome_DgghZtOEWm

I have created a data type for it:
image

Added the built-in values:

And in the calculation, you have to find the values of each selected in the multi-dropdown:
image

The format as text to apply some calculation to each element of the dropdown:

And when you are getting the value of a sports, you do the search for:

image

I hope this is clear :wink:

Here is the editor if this is what you need and you want to check details: Test for Forum 12 | Bubble Editor

The same method above from @hergin can be done with option sets.

Get an option set: Sport_Options → all options:filtered (display = INPUT) :first items value (results in the correct value)

It should not require many changes as this can be used in place of existing conditions. It’s a new way to arrive to the numerical value of a sport. Though hard to say without seeing what has been built.

Option Sets are a super power in bubble and I would recommend using them when possible and appropriate!

Option Set = custom library for your app, you have to manually set the value pairs, and you can reference other option sets too

1 Like

You are right @hi.luisacosta . Thanks. I gave it another look and doable with Multi-dropdown as well.

1 Like

Nice! Glad you figured it out! Much faster than searching the DB, also less WU units afaik

It is faster indeed. Good info.
chrome_QEWHhgUVlz

1 Like

Thanks, this moved me along a bit, but where I’m stuck now is that right now when users sign up, they choose from a text dropdown input, selecting “Basketball”, and then I want to be able to add up and display the sum of all of the number values associated with the text inputs the users selected. Added to that, there’s a yes/no data type and the text/number value should only be added to the sum if that data type is yes.

Thanks a lot for your thorough help on this, I’ve been learning a lot about option sets and multi select.

Please put an example sign up screen so I can understand better. It looks like a multidropdown to me. They will only select a bunch of sports.

The dropdown I’m talking about is the size option. Thanks for taking a look!

I don’t understand what all the numbers mean? It looks like you let them only select one size from the dropdown, which means only one corresponding number value will be used. If this is the case, you can use @hi.luisacosta’s suggestion because he showed how to do it with one dropdown:

In this case, you will still create the option set for the sizes you have, add value attributes as I showed in the previous messages (Converting text to numbers to add up - #8 by hergin), and finally you will get the corresponding number value by using the @hi.luisacosta’s expression which is All size options -> filtered by (the size dropdown value):first item:value.

Glad we’re able to push you in the right direction. At this point, it’d probably be easiest if you show actual screenshots from your editor so we can help you. Alternatively, you can share a temporary editor link so we can take a look for ourselves.