Forum Discussion

Pawan's avatar
Pawan
Frequent Visitor
3 years ago

Date Time Format Help

Hi Team,

 

Please can you help me to convert below date field into Date Time format in DAX to use in Tabular model.

Input:

 

Expected Output format:

 

 

12 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Pawan 

    please try

    CONVERT ( LEFT ( 'Table'[HistoryDateOld], 20 ), DATETIME )

    • Pawan's avatar
      Pawan
      Frequent Visitor

      Hi tamerj1  I am getting error like Can't convert value of type text to Datetime

      • tamerj1's avatar
        tamerj1
        Community Champion

        Pawan 

        Seems it is not recognizing the YYYY-MM-DD format. In this case am afraid that it has to be done manually by extracting the year, the month, the day using LEFT and MID functions wrapped by VALUE then using the DATE function to calculate the date out of them. 
        on the other hand you can use MID to extract the time wraped with CONVERT - TIME

        Then add the time to date like _date + _time

    • Anonymous's avatar
      Anonymous
      Not applicable

      It should be 19

      • tamerj1's avatar
        tamerj1
        Community Champion

        Anonymous 

        Could be. I thought the space counts. Probably not?

  • Anonymous's avatar
    Anonymous
    Not applicable

    If you do not need all datetime precision anywhere in the model, I suggest to format it in the source.

    • Pawan's avatar
      Pawan
      Frequent Visitor

      I don't have database accesss. i am looking for solution in DAX.

      • Anonymous's avatar
        Anonymous
        Not applicable

        What about PowerQuery?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Pawan 

    Maybe you can transfer data in power query, and change it as datetime type

    e.g:

     

     

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Pawan's avatar
      Pawan
      Frequent Visitor

      Hi Anonymous I am working on Tabular cube and loading into Power BI. I can apply onl dax Convertion in Tabular cube.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Pawan 

        You can try this code:

        Column = CONVERT(LEFT([Column1],19),DATETIME)

        Best Regards!

        Yolo Zhu

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.