Activity Forums Salesforce® Discussions How to do multiple if else statements in a formula field?

  • How to do multiple if else statements in a formula field?

    Posted by Naman on April 30, 2016 at 5:28 pm

    I have a picklist on my Contracts object, and the possible values are: 'contract type a', 'contract type b, 'contract type n', etc.... I want to setup a formula field where, If 'contract type a' is selected, then the value of the formula field is "x". If 'contract type b' is selected, then the value should be 'y', so on and so forth. If no value is selected, it should be '0'.

    I can get one If else to work, but am having trouble adding in the other conditions. Any help is much appreciated!

    Naman replied 8 years, 4 months ago 3 Members · 3 Replies
  • 3 Replies
  • Prakhar

    Member
    June 10, 2016 at 2:03 pm

    Hii Naman,

    You can create the formula using nested if-else condition. It would look something like this.

    If(ISPICKVAL(Name_Picklist_Field, 'contract type a'),'x',IF(ISPICKVAL(Name_Picklist_Field, 'contract type b'),'y','0')) and so on.

    Replace the Name_Picklist_Field with the name of your picklist field api name. This formula works for the text type value.

    You can modify it according to your own.

    Thanks.

  • Nick

    Member
    June 28, 2016 at 9:24 pm

    I have this scenario:

    abc_c  (A)+ def_c (West)  + ghi_c (Elite) = 90,o00

    abc_c (B)+ def_c(MidWest) + ghi_c (Preferred) = 50,000

    values in the () are values from a picklist. The custom api fields are picklists which contains various values. Whenever any of these combinations are selected, the final value should be the set value, e.g., 90,000.

    What would be the correct syntax to write this up, thanks in advance!

     

  • Naman

    Member
    June 30, 2016 at 12:39 pm

    Hi Nick,

    Here we can use "CASE" Formula function in the formula fields.

    CASE(CASE(abc_c, "A","A","B","B","") + CASE(def_c, "West", "West", "MidWest", "MidWest","") + CASE(ghi_c, "Elite","Elite","Preferred","Preferred","") , "AWestElite", 90000, "BMidWestPreferred", 50000,0)

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos