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
Epiwatson7
New Member

Help calculating age on a specific date

Hello all,

 

I have a column with DOB and need to find the person's age on June 1, 2019.  I figured it out but I wanted to see if anyone had a more concise way of coding it.

 

= Table.AddColumn(#"...", "6/1/2019", each "6/1/2019", type date),
= Table.TransformColumnTypes(#"...",{{"6/1/2019", type date}}),
= Table.AddColumn(#"...", "Subtraction", each Duration.Days([#"6/1/2019"]-[DOB]), Int64.Type),
= Table.AddColumn(#"...", "Age@June_1_2019", each [Subtraction]/365, type number),
= Table.TransformColumns(#"...",{{"Age@June_1_2019", Number.RoundDown, Int64.Type}}),

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

To know the total number of days, you may use this calculated column formula

=today()-[DOB]


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Christophe
Helper II
Helper II

The simplest way I can think of:

1. Select your DOB column

2. Select Add Column > Date > Age. Power Query will build for you the following formula:

= Table.AddColumn(#"Replaced Value1", "Age", each Date.From(DateTime.LocalNow()) - [DOB], type duration)

3. Replace DateTime.LocalNow() with your fixed date:

= Table.AddColumn(#"Replaced Value1", "Age", each Date.From("6/1/2019") - [DOB], type duration)

mahoneypat
Employee
Employee

You can add a custom column with this formula to get the age on 6/1/2019

 

= Duration.TotalDays(#date(2019,6,1) - [DOB])/364

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
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.