cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
msommerf Regular Visitor
Regular Visitor

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

Accepted Solutions
Super User II
Super User II

Re: Calculating age from a date and time

@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
Super User II
Super User II

Re: Calculating age from a date and time

@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

Highlighted
msommerf Regular Visitor
Regular Visitor

Re: Calculating age from a date and time

Many thanks Nathan. This worked a treat!

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors