Calculate Age in Dynamics 365 as Number of Years using Microsoft Flow

By | December 7, 2018

Introduction:

If we want to calculate the Age in a number of years using Birthdate field (i.e. Date type field) in CRM we can achieve this in multiple ways. Here we tried to achieve this functionality using MS Flow.

Below example is configured for contact entity and flow will trigger whenever the record is created in Contact Entity.

Go to Office 365 → Microsoft Flow

  • Click on ‘Create from Blank’ button, to create new Flow.
  • You will be redirected to below screen then click on ‘When a record is created’ option which is highlighted in below screenshot, to trigger Flow on create of Contact entity record.

  • After this you will be redirected to below screen, Please select Organization Name (Your CRM Organization) and Entity name (In this case we considered Contact entity)
  • After this, you need to add condition to check if Birthdate field is Empty or not to proceed.Below is fetch expression to validate the same.@empty(triggerBody()?[‘birthdate’])
  • We need to add an Action to update the record and calculate Age field value in a number of* years using from expression.To update record use highlighted action as shown in below screenshot:

After this you need to select Organization Name and Entity Name once again. Here we need to select one more field i.e. Record Identifier to uniquely identify the record which needs to be updated.

Follow below screenshot to set the Record Identifier, here we select Contact:

Click on ‘Show Advanced option’ as shown in below screenshot, to populate value of Age field:

Find Age field in list then click on “Add dynamic content” then add mentioned expression as below under “Expression” tab then click OK.

int(split(string(div(div(sub(ticks(utcNow()),ticks(triggerBody()?[‘birthdate’])),864000000000),365.25)),’.’)[0])

Conclusion:

Using the simple steps given above user can calculate the Age in Dynamics 365 CRM as a number of years using Microsoft Flow.

InoLink-QuickBooks-Integration-with-Microsoft-Dynamics-365-Dynamics-CRM

4 thoughts on “Calculate Age in Dynamics 365 as Number of Years using Microsoft Flow

  1. rl

    This will not calculate the correct age all the time. The age calculation will only be correct if utcNow() has passed the birth date for the given year ex) January 1, 1975 – June 18, 2019 = 44 years. If utcNow() is prior to the birth date for the given year, it will be inaccurate ex) September 1, 1975 – June 18, 2019 = 44 years per calculation, but should be 43 years.

    1. inogic

      Hi,

      I have updated the blog which will resolve the issue specified in the below comment.

      Earlier I used to subtract Birth Year from Current Year however, in the updated blog I started calculating differences between Current Date and Birthdate and converted that result in Years.

      Suppose,
      Current Date = 20 June 2019
      Birthdate = 25 June 1990
      Difference in day = 10587 (i.e. 28 Years)

      Let me know if you have any further queries.

      Thanks!

  2. Bob Hall

    But this will only show the age at point contact was created as I don;t see any dynamic update over time – so viewing the record a year later will still have same ‘age’ value as when record was created!

Comments are closed.