I was trying to enter the below formula into a new formula field to track Contract End Dates when compared to a picklist and date field, while incorporating leap years. But I hit a compile Limit, I am a solo admin and have very minimal developing skills. Thank you for your input!
DATE (
/*YEAR*/
YEAR( Customer_Installation_Completed_Date__c ) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c - 1)/12),
/*MONTH*/
CASE(MOD(MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c, 12 ), 0, 12, MOD(MONTH(Customer_Installation_Completed_Date__c)+ Contract_Term_Months__c, 12 )),
/*DAY*/
MIN(DAY(Customer_Installation_Completed_Date__c), CASE(MOD(MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c,12), 9, 30, 4, 30, 6, 30, 11, 30, 2,
/* return max days for February dependent on if end date is leap year */ IF(MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 400) = 0 || (MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 4) = 0 && MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 100) <> 0 ), 29,28), 31)) )
Customer_Installation_Completed_Date__c
is a date field and Contract_Term_Months__c
is a formula field with the following formula
CASE(
Contract_Term__c,
"12 months", 12,
"24 months", 24,
"36 months", 36,
"60 months", 60,
"N/A", null,
null)
Customer_Installation_Completed_Date__c
andContract_Term_Months__c
also formula fields? If so then adding the code from them will help people figure out a solution for you.Contract_Term_Months__c
is referenced in your formula it replaces that field name with the formula for that field. That is why you can hit the limit for seemingly small formulasCustomer_Installation_Completed_Date__c + ((Contract_Term_Months__c / 12) * 365)