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
Chelena
Regular Visitor

Birthday in human readable language

Good day

 

I'm a nurse working with with paediatric data. I want the column to display age  "2y; 1m; 4d" from age in days. My excel recipe for this is as follows, it works fine:

=INT([@Age]/365.2425)&"y; "
& INT(([@Age]-INT([@Age]/365.2425)*365.2425)/30.44)&"m; "
&INT([@Age]-INT([@Age]/365.2425)*365.2425-INT(([@Age]-INT([@Age]/365.2425)*365.2425)/30.44)*30.44)&"d"

 

I tried to do the following and it failed:

Int64.From([Age]/365.2425)&"y; "
& Int64.From(([Age]-Int64.From([Age]/365.2425)*365.2425)/30.44)&"m; "
&Int64.From([Age]-Int64.From([Age]/365.2425)*365.2425-Int64.From(([Age]-Int64.From([Age]/365.2425)*365.2425)/30.44)*30.44)&"d"

 

I will add the solution to my personal cookbook because I use it repeatedly for all sorts of dates.

 

Thank you for your time!

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@Chelena,

Directly create a calculated column using DAX below.

col = INT([Age]/365.2425)&"y; "
& INT(([Age]-INT([Age]/365.2425)*365.2425)/30.44)&"m; "
&INT([Age]-INT([Age]/365.2425)*365.2425-INT(([Age]-INT([Age]/365.2425)*365.2425)/30.44)*30.44)&"d"


1.JPG

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

@Chelena,

Directly create a calculated column using DAX below.

col = INT([Age]/365.2425)&"y; "
& INT(([Age]-INT([Age]/365.2425)*365.2425)/30.44)&"m; "
&INT([Age]-INT([Age]/365.2425)*365.2425-INT(([Age]-INT([Age]/365.2425)*365.2425)/30.44)*30.44)&"d"


1.JPG

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you Lydia @v-yuezhe-msft ! I must still get use to the BI interface. I was trying to do it by editing the query / Power Query because I'm more familiar with it. I didn't think of the modeling ribbon.

 

But if there is anybody out there that can solve this in (power) query, it will be appreciated.

 

Thank you for your time Lydia. I will use it a lot and in future and try and remember the modeling ribbon. Smiley Very Happy

rajulshah
Super User
Super User

Hello @Chelena,

 

From the description, I think you want to display age in days.

 

For that, you just have to add custom column in the table in 'Edit Queries' window.

 

Select the Dates column and click on 'Add Column' tab and click on 'Column from Examples', and under that option select 'From Selection'.custom column.png

You will get list of values you want to calculate. You can select age and will have age in days.

 

custom column.png

 Let me know if I missed something or need any further help.

 

Regards.

Thank you for your response @rajulshah.

 

I do have the age in days that I derived from Add column --> Date --> Age. I want to convert that age in days (766) to this:

"2y; 1m; 4d"

 

Thank you.

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.