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
msommerf
Helper III
Helper III

Calculating age from a date and time

Hi am fairly new to BI & DAX and am struggling to do what I think should be very simple.

 

I have the following measure:

Selected Value = DATEVALUE(Format(SELECTEDVALUE('Year Analysis'[EOY Date]),"DD/MM/YYYY"))
 
I have a column full of dates in my table which are birth dates
 
I simply want to calculate the age for each person (SelectedValue date - Birthdate)
I have tried to create a new column using:
 
Age = Datediff ([Selected Value],'fleet list'[Dob],year)
 
But I get the error message: Cannot Convert Value " of Type Text to Date
 
Both the Dob Column and my measure are of a type Date.
 
Can anyone help?
 
Kind regards
Mark.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@msommerf  - One potential issue:

The SELECTEDVALUE function only returns a value if there is a single value in the context. To make sure you only get a single value, you could use MAX instead.

Hope this helps,

Nathan

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@msommerf  - One potential issue:

The SELECTEDVALUE function only returns a value if there is a single value in the context. To make sure you only get a single value, you could use MAX instead.

Hope this helps,

Nathan

Many thanks Nathan. This worked a treat!

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.