Sunday, April 5, 2015

Calculate Age in Dynamics CRM

There are situations when there is a need to calculate the elapsed time between the two dates within Dynamics CRM. Here are a few scenarios where this calculation may be needed:
  • Calculate child’s age to determine the lesson plan for the child
  • Calculate number of days the invoice is outstanding
  • Calculate number of days the opportunity is in the current stage
At this time, Dynamics CRM does not have a feature to calculate the difference between two dates out of the box. Calculated fields feature in CRM 2015 does not support this calculation at this time. 

Note: Please see the comment below for an update for Dynamics CRM 2015 Online Update 1.

However, you can accomplish this using an ISV solution from North52.

Depending on your needs, you can use one of the following approaches for age calculation.

Display Age on Contact form
If you need to simply display age of a specific contact on the Contact form, you can create a North52 formula and display the result in HTML web resource placed on the form. You will find step by step instructions here.
Calculate Days in Stage
There are situations where user not only needs to see this calculation for a specific record on the form but also on the views and charts and use the result in the filter criteria for searching. In this case, the result needs to be calculated and stored in a field in CRM. You will need to create a field in CRM and use North52 Process Genie and Scheduler to update it. Step by step instructions can be found here.
In addition to the above two methods, if you have a large volume of records that needs to be updated daily, you can create a SQL job to update the field each day. However, note that direct update to the database (as in this approach) is not supported.

Please also see the related article Storing and Querying Age in Dynamics CRM.