1

EDIT:

CASE( cycle__c, 
'Monthly', ADDMONTHS (selected_date__c, 1),
'Yearly', 

IF(
    AND(
        MONTH(selected_date__c) = 2,
        DAY(selected_date__c) = 29
    ),
    DATE(YEAR(selected_date__c)+ 1, 3,1),
    DATE(YEAR(selected_date__c) + 1, MONTH(selected_date__c), DAY(selected_date__c))
), 
DATE(YEAR(selected_date__c)+ 1, 3,3),
    DATE(YEAR(selected_date__c) + 1, MONTH(selected_date__c), DAY(selected_date__c)),
Null //Default
)

I have standard Salesforce page and I have two fields which user will choose from the first field (selected_date__c) is the date and second field (cycle__c) is the picklist and based on those two selections, I need to show the calculate_date__c

example:

selected_date__c = 7/17/2022
cycle__c = Monthly

the calculate_date__c should be 8/17/2022 (because cycle__c selection was monthly so added one month to it)

another example:

selected_date__c = 7/17/2022
cycle__c = Yearly

the calculate_date__c should be 7/17/2023

I need to show the calculate_date__c, is that possible using formula field or do I need to think of using Flow?

1 Answer 1

1

You can use the Case function in formula field to achieve this as follows,

CASE( cycle__c, 
'Monthly', ADDMONTHS (selected_date__c, 1),
'Yearly', 

IF(
    AND(
        MONTH(selected_date__c) = 2,
        DAY(selected_date__c) = 29
    ),
    DATE(YEAR(selected_date__c)+ 1, 3,1),
    DATE(YEAR(selected_date__c) + 1, MONTH(selected_date__c), DAY(selected_date__c))
),
piclist value 3 , Outcome/Result 3, //you can add more additional logic on here
Null //Default
)

Thanks.

7
  • great, so I add another option something like simiyearly next to the yearly but it throws an error Incorrect number of parameters for function 'CASE()'. Expected 6, received 7 (Related field: Formula)
    – Nick
    Feb 16, 2022 at 13:31
  • If you adding another one option means please add into the correct format, as follows, value 3, Result 3 before the default option.
    – Raj
    Feb 16, 2022 at 13:35
  • what is the value 3, result 3, add the logic after the if condition you mean? or can you edit the answer please?
    – Nick
    Feb 16, 2022 at 13:38
  • add the logic after the if condition you mean? - Yes, I have updated the answer now. Please Check.
    – Raj
    Feb 16, 2022 at 13:42
  • I updated my question please see if this make sense but i'm getting syntax error though.
    – Nick
    Feb 16, 2022 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .