How to Calculate Age in Years in Dynamics 365?

Previously, if you wanted to calculate the age of a person in Dynamics 365 (or Dataverse), you could create a calculated column. However, when using the DiffInYears function, the result would be rounded up. So if Pat was born on 1st Jan 2000 and today was 10th Dec 2019, the system would round 19.92 years to 20 years. So, to work around this and get the appropriate age, developers would write plugins or JavaScripts, or create multiple fields to work out the calculations.

The New Method​

As part of the low code initiative, Microsoft has enabled Formula columns within Dynamics 365 (or Dataverse). This enables us to Power Fx formulas (similar to Excel formulas) that are calculated during fetch operations.
This allows us to use functions like RoundDown, DateDiff and UTCNow. So, to calculate the age of a contact, we can create a new column of the type ‘Formula’ and use the following formula: RoundDown(DateDiff(Birthday, UTCNow(), TimeUnit.Years),0) And just like that, what was previously code, is now low-code 🙂
If you found this useful, consider subscribing to our weekly newsletter where we share more such tips, tricks and updates on Dynamics 365 and Power Platform.

Discover more from Power x 365

Subscribe now to keep reading and get access to the full archive.

Continue reading