Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Text to Date M-Query

Hi Team,

I'm trying to convert text to date format however i can't get proper result.

 

Look like Month have text data type.

 

i need  "MMM-YY" format with M Query (or) DAX.

 

Thanks,

KV's

 

 

  • Anonymous , what is data type of month as of now. It is date then you can change display format or try this as new column

     

    New Format = format([month],"MMM-YY")

     

    if it text then try like

    New Date = "01-" & left([month],3) & "-" & right([Month],2)  // Change data type to date then

    New Format = format([New Date],"MMM-YY")

3 Replies

  • nvprasad's avatar
    nvprasad
    Solution Sage

    Hi,

    You can split the current format into month & year ( Jan, 20 ) then use Date.Fromtext to add a new column. Once the desired column is ready you can delete Month & Year columns.

     

    Please refer to link.

    https://docs.microsoft.com/en-us/powerquery-m/date-fromtext

     

    Appreciate a Kudos! 🙂
    If this helps and resolves the issue, please mark it as a Solution! 🙂

    Regards,
    N V Durga Prasad

    • nvprasad's avatar
      nvprasad
      Solution Sage

      Hi,

      You can split the current format into month & year ( Jan, 20 ). Use If function in M code to convert month name to number ( Jan to 1, Feb to 2) then use Date.Fromtext to add a new column.  Once the desired column is ready you can delete Month & Year columns.

       

      Please refer to the link.

      https://docs.microsoft.com/en-us/powerquery-m/date-fromtext

       

      Appreciate a Kudos! 🙂
      If this helps and resolves the issue, please mark it as a Solution! 🙂

      Regards,
      N V Durga Prasad

  • Anonymous , what is data type of month as of now. It is date then you can change display format or try this as new column

     

    New Format = format([month],"MMM-YY")

     

    if it text then try like

    New Date = "01-" & left([month],3) & "-" & right([Month],2)  // Change data type to date then

    New Format = format([New Date],"MMM-YY")