Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

How do I create a date field using a text field that has year and month only.

I have a text field that contains year and month only (ex '201801'). How do i create a date field using this text field.

 

Thanks!

Sallee

  • Well, in DAX you could do this:

     

    Column = DATE(INT(LEFT([Column1],4)),INT(RIGHT([Column1],2)),1)

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Well, in DAX you could do this:

     

    Column = DATE(INT(LEFT([Column1],4)),INT(RIGHT([Column1],2)),1)
  • Sallee,

     

    create a new column in same table with following code where varible _Date  can be equal to other column in a table with dates.

     

    3rd argument of the DATE function defines a day. In my case the result will be 1/1/2018

     

    =
    VAR _Date = "201801"
    RETURN
    DATE(left(_Date,4),MID(_Date,5,2),1)

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, I have this formula

      Businessdate = DATE(LEFT([BUS_YEAR_MTH],4),MID([BUS_YEAR_MTH],5,2),1)

       

      but it is giving me this error:

      Expression.Error: The name 'DATE' wasn't recognized. Make sure it's spelled correctly.

       

      Thanks for your help!

      Sallee