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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Calculating age from a date and time

I'd be extreemly grateful if someone could help with this. I have a column containing date and time information. From this I need to create a new column which shows the age based on the date (in days).

 

 

I also have a seperate dataset with a start date and end date (date and time) which I need to calculate the days between the start and end.

 

1 ACCEPTED SOLUTION

@Anonymous

 

Use "New Column" not "New Measure"




Lima - Peru

View solution in original post

12 REPLIES 12
RayL
Advocate I
Advocate I

FYI-

 

another quick way to convert DOB to age:

  1. In Query Editor> select the column that contains DOB 
  2. Go to Date & Time Colmn section > Date> Select "Age"
  3. In Date & Time Colmn section > Duration > Select "Total Years"
  4. Highlight the transformed column, right click and select "Change Type"> Select "Whole Number"
  5. Rename the column

What a Fantastic Way @RayL, Many thanks for Sharing.!

I had similar requirement of calculating age from DOB. 

This is the easiest way to implement.

 

Thank you!!

One issue with this method is that for anyone that is over 6 months into their "current" age, their age will be rounded up. E.g. 26.7 will be rounded up to 27.

 

The solution to this is before you convert the column to a whole number, instead right click on the column header and go to Transform -> Round -> Round Down.

Vvelarde
Community Champion
Community Champion

@Anonymous

 

hi,

 

To calculate the age in Days:

 

Age = DATEDIFF(Table1[DateTimeColumn],TODAY(),DAY)

 

to calculate the days between the start and end.

  

DaysBetween = DATEDIFF(Table1[StarDate],Table1[EndDate],DAY)




Lima - Peru

Hello,

 

If I then wanted to create a measure of the AVERAGE of all the "ages" how would I achieve this?

 

I used the Query Editor to "Insert a Custom Column" (Add Column tab).  I inserted the formula given here, but PowerBI doesn't seem to like the DATEDIFF function.  The system inserted the Table.AddColumn bit up to the DATEDIFF.

= Table.AddColumn(#"Removed Columns", "ItemAge", each DATEDIFF([FirstDetected],TODAY(),DAY))

 Advice welcome.

Anonymous
Not applicable

Thanks you...

 

I seem to have done something wrong (assuming it's me as a newbie):

 

21-04-2017 09-02-41.png

@Anonymous

 

Use "New Column" not "New Measure"




Lima - Peru

Who wants an age in days? This is a silly solution!

Anonymous
Not applicable

Thank you for taking the time to help me, it's much appreciated.

 

 

My best guess is that you need to choose "New Column" first.

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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