Forum Discussion

SachinC's avatar
SachinC
Helper V
6 years ago
Solved

Convert string Date Value to Date Type (using Direct Query)

Hi all, I tried this and it wants to convert the Dataset to mixed mode - Import and Direct Query. I want this to be Direct Query only. My date value is: 2019-12-30T00:00:00 Please help! Thanks. ...
  • v-juanli-msft's avatar
    v-juanli-msft
    6 years ago

    Hi SachinC 

    As tested, it doesn't support to convert text to date format in Power query when connection type is direct query.

    You could add a calculated column on report view, or change date format in sql side.

    Column =
    VAR t_number =
        FIND (
            "T",
            [date],
            1,
            0
        )
    VAR date_text =
        LEFT (
            [date],
            t_number - 1
        )
    VAR year_t =
        LEFT (
            date_text,
            4
        )
    VAR first =
        FIND (
            "-",
            date_text,
            1,
            0
        )
    VAR second =
        FIND (
            "-",
            date_text,
            first + 1,
            0
        )
    VAR interval = second - first - 1
    VAR mm =
        MID (
            date_text,
            first + 1,
            interval
        )
    VAR dd =
        RIGHT (
            date_text,
            t_number - second - 1
        )
    RETURN
        year_t & "/" & mm & "/" & dd
    

    For better performance, you could change format in sql server side.
     
    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.