Forum Discussion

Chelena's avatar
Chelena
Regular Visitor
8 years ago
Solved

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!

  • Anonymous's avatar
    Anonymous
    8 years ago

    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"




    Regards,
    Lydia

4 Replies

  • rajulshah's avatar
    rajulshah
    Resident Rockstar

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

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

     

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

     

    Regards.

    • Chelena's avatar
      Chelena
      Regular Visitor

      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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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"




    Regards,
    Lydia

    • Chelena's avatar
      Chelena
      Regular Visitor

      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. :smileyvery-happy: