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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Bfaws
Helper III
Helper III

Issues with rounding on date calculations and rounding down function

Hello, 

 

I hope some can help.

 

I have some calculation that calculate a persons age based on two columns.  I create a custom column with the following measure:

 

[Report Date] - [Birthdate]

 

This gives a column with the number of days between - this figure produced looks correct.  I then add another column changing the days to years using the Time function to change the days to years - this then gives and incorrect figure because it simply divides the days by 365 not taking into account leap years etc.

 

For example

 

[30/04/2022] - [13/05/1962] = 21902 days.  His age on 30/04/2022 should be 59 but the days to years does the following:

 

21902/365 = 60.005

 

Any help getting a more accurate figure would be much appreciated.

 

Thanks, 

 

Bfaws

1 ACCEPTED SOLUTION
ferhat_lyes
Frequent Visitor

use this dax formula : 

Age DateDiff = INT ( YEARFRAC ( DATE(2022,4,30), DATE(1962,05,13), 1 ) ) it will gives you 59 
and 
this formula : 
Age DateDiff = DATEDIFF(DATE(2022,4,30),DATE(1962,05,13),YEAR) gives 60 
 
Hope that will help you 😄 

View solution in original post

3 REPLIES 3
ferhat_lyes
Frequent Visitor

use this dax formula : 

Age DateDiff = INT ( YEARFRAC ( DATE(2022,4,30), DATE(1962,05,13), 1 ) ) it will gives you 59 
and 
this formula : 
Age DateDiff = DATEDIFF(DATE(2022,4,30),DATE(1962,05,13),YEAR) gives 60 
 
Hope that will help you 😄 

Many thanks works perfectly for 59 years

Scala
Regular Visitor

Hello! Have you tried using the DAX-function DATEDIFF? I think this should be able to give you the value you want: DATEDIFF([Report Date],[Birthdate],YEAR)

 

Edit: actually it looks like datediff rounds up, so you would have to round down the result. You might be able to find additional ways of dealing with this in the following thread: Solved: Age and Age intervals, 3 questions - Microsoft Power BI Community

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.