Showing results for 
Search instead for 
Did you mean: 
Super User
Super User

Calculating age in CDS entity

I could not find a simple solution to calculating age in a model driven app using a CDS entity because there is no RoundDown() function like there is in Canvas apps.  I was able to accomplish it by using two fields to create the third. crabe_dob is the Date of Birth field in the entity.  The first field (Age0) was a whole number calculated field with the formula



 DiffInDays(crabe_dob, Now()) / 365



This created a whole number that was automatically rounded up. 

The second field (Age1) was a decimal field with the same formula.  

The third field (Age) was a whole number field contained the following conditional formula



If Age0 is greater than Age1 then Set Age to  Age1 - 1
Else Set Age to Age0



Other solutions that I found involved using Flow, C++ or Javascript and I wanted to keep it simple for myself. Other commenters even said it wasn't possible OOB in Dynamics 365. 

Community Support
Community Support

Hi @Drrickryp ,

I agree with your solution. Thanks for your sharing. If you have other questions about PowerApps, please feel free to reply here.


Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for posting the solution. There is one edge case where it may not work though, as it doesn't take into account leap years. A closer function would be the following, assuming that you're dealing with people who are currently alive (as the year 2000 is a leap year, but 1900 is not) 

DiffInDays(crabe_dob, Now()) / 365.25

Thanks @DavidJennaway .  That fixes it for leap years.

Helpful resources

Ignite 2022


Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (1,878)