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
SFDC_2706SFDC_2706 

Calculate formula with adding months

Hi All,

I need quick advice on this following item. I need to calculate new formula field which will add 1 month, 3 months, 6 months, 1 year and none from the existing due date field when picklist field is selected as below:

Formula example :
If Picklist value is selected 'Annually' then formula would be (Due_Date__c + 1 Year)

Annually : Due_Date__c + 1 Year
Half-yearly : Due_Date__c + 6 Months
Quarterly : Due_Date__ct + 3 Months
Monthly : Due_Date__c + 1 Month
None : Blank

Looking forward for the quick help and thanks in advance..!!

AnkaiahAnkaiah (Salesforce Developers) 
Hi,

This example formula adds two months to a given date. You can modify the conditions on this formula if you prefer different behaviors for dates at the end of the month.
DATE(
  YEAR( date ) + FLOOR( ( MONTH ( date ) + 2 - 1 ) / 12 ),
  MOD( MONTH ( date ) + 2 - 1 + 
    IF( DAY ( date ) > CASE( MOD( MONTH( date ) + 2 - 1, 12 ) + 1, 
      2, 28,
      4, 30,
      6, 30,
      9, 30, 
      11, 30,
      31 ), 1, 0 ), 12 ) + 1,
    IF( DAY( date ) > CASE( MOD( MONTH( date ) + 2 - 1, 12 ) + 1,
      2, 28, 
      4, 30, 
      6, 30, 
      9, 30, 
      11, 30, 
      31 ), 
    1, DAY( date )
  )
)

Refer the below link

https://help.salesforce.com/s/articleView?id=sf.formula_examples_dates.htm&type=5

If this helps, Please mark it as best answer.

Thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code 
If(ISPICKVAL(Piclist__c,"Annually"),ADDMONTHS(Due_Date__c, 12),
    if(ISPICKVAL(Piclist__c,"Half-yearly"),ADDMONTHS(Due_Date__c, 6),
	   if(ISPICKVAL(Piclist__c,"Quarterly"),ADDMONTHS(Due_Date__c, 3),
		  if(ISPICKVAL(Piclist__c,"Annually"),ADDMONTHS(Due_Date__c, 1),''))))

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
SFDC_2706SFDC_2706

Hey,

Thanks for your replies. Really appreciate it. I tried with below formula and it worked. Similar as yours but used CASE function instead of multiple if's.

CASE(GAM_RecurrenceFrequency__c,
"Monthly", ADDMONTHS(RocketDocs__Due_Date__c,1) ,
"Quarterly", ADDMONTHS(RocketDocs__Due_Date__c,3),
"Half Yearly", ADDMONTHS(RocketDocs__Due_Date__c,6),
"Annually", ADDMONTHS(RocketDocs__Due_Date__c,12), null)

AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Thanks fro the update.

If my answer helps, Please mark it as best answer.

Thanks!!

 
TRIB JAMETRIB JAME
GREAT ANSWER