Search code examples
salesforcesalesforce-lightning

How to calculate if Date is more than "2 years ago" with a Salesforce formula field?


I need to calculate in a custom field if a Date is more than 2 years ago ... if so then return a YES or if it is not then return a NO

I'm trying this formula, making the return type "text" Last_won_deal_date__c > DATEVALUE("2 years ago") but it's giving the following error:

Error: Formula result is data type (Boolean), incompatible with expected data type (Text).


Solution

  • There are lots of sample formulas that could get you started: https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=5 (check the "Finding the Number of Days Between Two Dates" part)

    Try IF(Last_won_deal_date__c < TODAY() - 2 * 365, 'YES', 'NO') or some variations of it.