Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Mckenzie--Cl
New Member

Calculating age using 2 dates and then rounding down

I'm trying to calculate the age of people at the time they were diagnosed with a health condition.  I have 2 dates, date of birth and date of diagnosis.  I've managed to do this using DATEDIFF but some of the ages being returned are wrong.  For example a person born on 1/12/1968 would have been 53 when they were diagnosed on 11/01/2022, however the DATEDIFF is returning an age of 54.  Is there a way that the number returned is rounded down to reflect the actual age at the time of being diagnosed?  Thanks.

2 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

The reason DATEDIFF isn't working is because it counts the number of boundaries which have been crossed between the two dates, its not working to a particular number of days. A DATEDIFF between 31st Dec and 1st Jan gives 1 year, as 1 boundary has been crossed.

You could try instead using

Age =
YEAR ( 'Table'[Date of diagnosis] - 'Table'[Date of birth] ) - 1900

View solution in original post

Ahmedx
Super User
Super User

4 REPLIES 4
Ahmedx
Super User
Super User

pls try this

Screenshot_3.png

That seems to have worked!  Thanks very much Ahmedx.

johnt75
Super User
Super User

The reason DATEDIFF isn't working is because it counts the number of boundaries which have been crossed between the two dates, its not working to a particular number of days. A DATEDIFF between 31st Dec and 1st Jan gives 1 year, as 1 boundary has been crossed.

You could try instead using

Age =
YEAR ( 'Table'[Date of diagnosis] - 'Table'[Date of birth] ) - 1900

That has worked.  Thanks very much Johnt75.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.