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
Namgyal SchaafNamgyal Schaaf 

Keep getting errors with my nested if statement

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?
Best Answer chosen by Namgyal Schaaf
mritzimritzi
I modified your logic, made changes  and now it's working for me (for Account's Object)
IF(  
	AND(ISPICKVAL( Industry , 'QBO'), Name  = 'ABC')  ,
	TODAY() + 10 + 5,
	IF(
		AND(ISPICKVAL( Industry , 'QBO'), Name  = 'XYZ')  ,
		TODAY() + 19 + 5,
		IF(
			AND(ISPICKVAL( Industry , 'INTACCT'), Name  = 'ABC')  ,
			TODAY() + 18 + 5*3,
			IF(
				AND(ISPICKVAL( Industry , 'INTACCT'), Name  = 'XYZ')  ,
				TODAY() + 27 + 5*3,
				NULL
			)
		)
	)
)

Adaptation to your requirements is as follows:
 
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
			)
		)
	)
)

I hope that "Salesforce_required_for_Go_Live__c" is a checkbox and Number_of_Subsidiaries__c is Number field with 0 decimal places.

Please make field name changes (if required) to suit your need.

If this solves your problem, please mark it as Best Answer

All Answers

mritzimritzi
I modified your logic, made changes  and now it's working for me (for Account's Object)
IF(  
	AND(ISPICKVAL( Industry , 'QBO'), Name  = 'ABC')  ,
	TODAY() + 10 + 5,
	IF(
		AND(ISPICKVAL( Industry , 'QBO'), Name  = 'XYZ')  ,
		TODAY() + 19 + 5,
		IF(
			AND(ISPICKVAL( Industry , 'INTACCT'), Name  = 'ABC')  ,
			TODAY() + 18 + 5*3,
			IF(
				AND(ISPICKVAL( Industry , 'INTACCT'), Name  = 'XYZ')  ,
				TODAY() + 27 + 5*3,
				NULL
			)
		)
	)
)

Adaptation to your requirements is as follows:
 
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
			)
		)
	)
)

I hope that "Salesforce_required_for_Go_Live__c" is a checkbox and Number_of_Subsidiaries__c is Number field with 0 decimal places.

Please make field name changes (if required) to suit your need.

If this solves your problem, please mark it as Best Answer
This was selected as the best answer
Namgyal SchaafNamgyal Schaaf
Thanks a bunch this is working! Do you mind pointing out what changes you've made - I still dont understand what I'm doing wrong. 
mritzimritzi
You were using the fomulas & the closing braces incorrectly.