Forum Discussion

renanc's avatar
renanc
Helper II
6 years ago
Solved

Error to convert nvarchar to Datetime

When the power query tries to integrate data through the SQL source, a power bi date conversion error appears. It is important to note that the SQL query is not giving problems, I checked in SQL software.
This is (probably) when power bi tries to convert nvarchar data to date because the date is (probably) in PBI text format.

 

Conversion errorSQL table/query source

(Table) - Source from power query: 

Fonte = Sql.Database("serverx", "xx"),
dbo_vw_PS = Fonte{[Schema="dbo",Item="dbo_vw_PS"]}[Data],
#"Linhas Filtradas" = Table.SelectRows(ddbo_vw_PS, each [DataMovimentacao] > #datetime(2019, 6, 1, 0, 0, 0)),

 

4 Replies

  • AnkitBI's avatar
    AnkitBI
    Solution Sage

    Is your Date in SQL stored as NVarchar ? Also, share some sample data, may be just dates from SQL

    • renanc's avatar
      renanc
      Helper II

      AnkitBI the issue was solved, the problem was indeed inside a SQL account view (the one linked in power bi) whose didnt have the correct datetime in english to portuguese.

      In one of the sql accounts the table was loading properly, so we checked and converted to the same datetime and worked (that's why I said in SQL was ok, because indeed it was, but not in the one which was linked with BI).

      Lol.. thank you guys, and sorry to waste your time, the whole issue was rooted in SQL.

  • v-juanli-msft's avatar
    v-juanli-msft
    Community Support

    Hi renanc 

    Could you show me the date format in SQL Database?

    Maybe we need do some transformation for the date column.

     

    There are some similar thread you could refer to

    https://community.powerbi.com/t5/Desktop/Microsoft-Sql-converting-data-type-varchar-10-to-int-only-in/td-p/328443

     

     

    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.

     

    • renanc's avatar
      renanc
      Helper II

      v-juanli-msft  the issue was solved, the problem was indeed inside a SQL account view (the one linked in power bi) whose didnt have the correct datetime in english to portuguese.

      In one of the sql accounts the table was loading properly, so we checked and converted to the same datetime and worked (that's why I said in SQL was ok, because indeed it was, but not in the one which was linked with BI).

      Lol.. thank you guys, and sorry to waste your time, the whole issue was rooted in SQL.