[SalesForce] How to use formula to transform text to integer

I want to use a dropdown list for attributing values to a field. However, for the end user, I want to show easy labes instead of numbers.

I wonder how I can set up a formula to transform that text to integers.

The labels would be: easy, medium and hard. They should be mapped to 0.5, 1 and 1.5.

I need to transform those to compute them in another formula.

Here is what it would look like in a basic Python function:

def mapping(x):
    y = 1
    if x == 'easy':
         y = 0.5
    elif x == 'medium':
         y = 1
    else:
         y = 1.5

How can I solve this using formulas in Salesforce?

Best Answer

if you wanted the user to choose from text values in the picklist, you could do a conversion to numeric factor in the formula itself, using the CASE function.

Suppose you have the three picklist values 'Easy', 'Medium', 'Hard' then you could rewrite your formula field as

amount__c * CASE(Boost_Factor__c, 'Easy', 0.5, 'Medium', 1, 'Hard', 1.5, 1)   //final argument is the default if no match
Related Topic