Forum Discussion

powerbidev123's avatar
powerbidev123
Solution Sage
19 days ago
Solved

Dax help

Age = YEAR(UTCNOW())- MID('Application'[Date of Birth],7,4) . here MID('Application'[Date of Birth],7,4) is text value , how can i make it integer in dax in the same formula

  • Wrap the MID with VALUE() to convert the text to a number:

     

    Age = YEAR(UTCNOW()) - VALUE(MID('Application'[Date of Birth], 7, 4))

     

    INT() also works, but VALUE is the more idiomatic choice when the string is a plain number.

     

    One heads up: if [Date of Birth] is actually a date column you can skip MID entirely and just use YEAR('Application'[Date of Birth]). Also bear in mind this returns a rough age based on year only, without checking whether the birthday has passed this year.

     

    If this helped, a thumbs up and accepting the solution would be appreciated.

     

    Thanks,
    Shai Karmani

     

    Let's connect in LinkedIn

4 Replies

  • Wrap the MID with VALUE() to convert the text to a number:

     

    Age = YEAR(UTCNOW()) - VALUE(MID('Application'[Date of Birth], 7, 4))

     

    INT() also works, but VALUE is the more idiomatic choice when the string is a plain number.

     

    One heads up: if [Date of Birth] is actually a date column you can skip MID entirely and just use YEAR('Application'[Date of Birth]). Also bear in mind this returns a rough age based on year only, without checking whether the birthday has passed this year.

     

    If this helped, a thumbs up and accepting the solution would be appreciated.

     

    Thanks,
    Shai Karmani

     

    Let's connect in LinkedIn

  • v-achippa's avatar
    v-achippa
    Community Support

    Hi powerbidev123,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you Shai_Karmani and Greg_Deckler for the prompt response.

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked?  or let us know if you need any further assistance.

     

    Thanks and regards,

    Anjan Kumar Chippa