function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael Bresloff 7Michael Bresloff 7 

How to do multiple if else statements in a formula field

Hi all - forgive the "noob" question

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!

 
Vivek DVivek D
I will suggest CASE as a function 
// syntax for case is  
// CASE(expression,​value1, result1, value2,​ result2,...,​ else_result

CASE(1, 
IF(ISPICKVAL​ (MyField__c, "SomeValue1"),​ 1, 0) , value1 ,​​
IF(ISPICKVAL(MyField__c, "SomeValue2"), 1, 0),​​value2 , 
 // And so on
IF(ISPICKVAL(MyField__c, "SomeValueN"), 1, 0),​​valueN ,
// At last of nothing match 
FinalValueIfnothingMatch
)

 
mritzimritzi
Formula (return type text):
 
IF( ISPICKVAL( Field_Name__c , 'Vlaue1') , 'AAA',
IF( ISPICKVAL( Field_Name__c , 'Value2') , 'BBB',
IF( ISPICKVAL( Field_Name__c , 'Value3') , 'CCC',
''
)))

AAA,BBB,CCC are values that would returned  be based on picklist filedvalues (value1, value2, value3, etc)
Close the conditions with equal no of round braces.



Hit LIKE if this helps, Select it as BEST ANSWER if it solves your problem.
Parker EdelmannParker Edelmann
If you decide to use a CASE() function, which for a picklist is the easiest, use this syntax:
CASE(Contract_Type__c,
                      "contract type a", number1,
                      "contract type b", number2,
                      "contract type n", number3,
/*And so on and so forth until you don't have or don't want to put any more values*/
                      0)
The CASE() function is one of few that work with single-select picklists, and references the picklist only once, as opposed to multiple if-then statements. To show you what that would look like, not that I recommend that, but only for future reference when CASE() is not possible, here's that syntax:
IF(ISPICKVAL(Contract_Type__c, "type a"), x, IF(ISPICKVAL(Contract_Type__c, "type b"), y, z))
If you wished, you could put another If statement where x, y, or z are to account for different situations. You may also use them within CASE() as well. If this helps you, please let me know or mark as best.

Thanks,
Parker
Namgyal SchaafNamgyal Schaaf
Hey There, I'm trying to use a IF statement or a case statement and am having some trouble. I have a date field, and want to create a forumula field that creates a new date based on my criteria. Below is my formula:

IF(AND(ISPICKVAL(ERP__c,"QBO"), Salesforce_required_for_Go_Live__c = FALSE),Opportunity_Close_Date__c + 10 + Number_of_Subsidiaries__c, 
IF(AND (ISPICKVAL(ERP__c,"QBO"), Salesforce_required_for_Go_Live__c = TRUE), Opportunity_Close_Date__c + 19 + Number_of_Subsidiaries__c),
IF(AND (ISPICKVAL(ERP__c,"INTACCT"), Salesforce_required_for_Go_Live__c = FALSE), Opportunity_Close_Date__c + 18 + Number_of_Subsidiaries__c*3),
IF(AND (ISPICKVAL(ERP__c,"INTACCT"), Salesforce_required_for_Go_Live__c = TRUE), Opportunity_Close_Date__c + 27 + Number_of_Subsidiaries__c*3),
NULL)

Error is:  Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2

Any thoughts?
 
Namgyal SchaafNamgyal Schaaf
Ok thanks!
brianna davidsonbrianna davidson

i tried doing this, but i am getting an unknown syntax error. does anyone know whats going on? I am trying to populate a product code (number) from user input of product (name). 

IF(ISPICKVAL(Z_Product__c, “Dental Office”), 55), 
IF(ISPICKVAL(Z_Product__c, “Pre-Sold”), 167),
IF(ISPICKVAL(Z_Product__c, “One Time Close”), 2287)

Derek Hoffritz 10Derek Hoffritz 10
Try this:
IF(ISPICKVAL(Z_Product__c, “Dental Office”), 55), 
IF(ISPICKVAL(Z_Product__c, “Pre-Sold”), 167),
IF(ISPICKVAL(Z_Product__c, “One Time Close”), 2287),
NULL)
Akshay BarangeAkshay Barange
first 3 condition soved but in technical validation i get error how  to solve it

If Deal Stage = Preliminary and (Payment Terms = Null AND Line Item Count = 0) then P = 0%
OR
If Deal Stage = Preliminary and (Payment Terms = Null OR Line Item Count = 0) then P = 0%,
else
If Deal Stage = Preliminary and (Payment Terms <> Null AND Line Item Count > 0) then P = 5%,

SBQQ__PaymentTerms__c----> picklist



If Deal Stage = Technical Validation AND If tech approval status(D) <> Approved,  then P = 20%
OR
    CPQ_Technical_Review_Status__c-->>picklist
CPQ_CBS_Technology__c----> picklist

If Deal Stage = Technical Validation AND If Technology is NULL then P = 20%
else 
IF If Deal Stage = Technical Validation, then P = 25%

IF( AND(ISPICKVAL(Deal_Stage__c ,"Preliminary") , AND(ISPICKVAL(SBQQ__PaymentTerms__c, "") , SBQQ__LineItemCount__c  = 0 ) ),
0, IF(OR(ISPICKVAL(Deal_Stage__c, "Preliminary"), OR(ISPICKVAL(SBQQ__PaymentTerms__c, ""), SBQQ__LineItemCount__c = 0)),0,IF( ISPICKVAL(Deal_Stage__c ,"Preliminary") && !ISPICKVAL(SBQQ__PaymentTerms__c, "") && SBQQ__LineItemCount__c> 0,0.5,IF(ISPICKVAL(Deal_Stage__c, "Technical Validation") && !ISPICKVAL(CPQ_Technical_Review_Status__c, "Approved"), 0,0.2))))