This knowledge article walks you through creating a formula field in Salesforce that calculates the number of months between a start date and today, but only when your desired picklist value is selected. Once the picklist value changes, the calculation stops, ensuring accuracy and preventing outdated data from displaying.
To calculate the duration in months from a start date to today when a specific picklist value is selected, follow the steps below :
Step 1:
Step 2:
Step 3:
IF(
ISPICKVAL(PotentialLiability__c, "Yes"),
(YEAR(TODAY()) - YEAR(Start_Date__c)) * 12 + (MONTH(TODAY()) - MONTH(Start_Date__c)),
0)
Step 4:
Note : For more complex requirements, such as handling multiple picklist values or including partial months in the calculation, the formula can be further customized. You may also consider using a validation rule to ensure the start date is not in the future if that's a business requirement. Remember that formula fields are calculated at runtime and do not store data, so they're ideal for this type of dynamic duration calculation.
004695734

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.