Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
renanc
Helper II
Helper II

(Error to convert nvarchar to Datetime) Conversão de dados tipo nvarchar para datetime: PowerQuery M

Quando a power query tenta integrar os dados através da fonte/source SQL aparece um erro de conversão de data por parte do power bi.
É importante observar que na query do SQL não está dando problemas, eu verifiquei.
Provavelmente é quando o power bi tenta converter os dados nvarchar para data porque provavelmente a data está em formato de texto para o PBI.

 

Erro de conversãoErro de conversãoExemplo de estratificação da table direto na fonte do SQLExemplo de estratificação da table direto na fonte do SQL


Query (atual) pelo M: 

 

 

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)),

 


Spoiler
Também vou acrescentar alguns passos que já foram feitos na tentativa de me ajudar em outro forum, MAS não deram certo:

 

1)

 

 

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

 


e segunda tentativa:
2)

 

let
Fonte = Sql.Database("serverx", "xx"),
dbo_vw_PS = Fonte{[Schema="dbo",Item="dbo_vw_PS"]}[Data],
CastToDate =
Table.TransformColumns( // Note we're using Table.TransformColumns instead of Table.TransformColumnTypes
dbo_vw_PS,
{{"DataMovimentacao", each DateTime.FromText(_, "pt-BR"), DateTime.Type}}),
#"Linhas Filtradas" =
Table.SelectRows(
CastToDate,
each [DataMovimentacao] > #datetime(2019, 6, 1, 0, 0, 0)),

 


 Obs: esses passos acima deram problema no ciclo através da linguagem M.


Obrigado!

 

 

3 REPLIES 3
renanc
Helper II
Helper II

ADDING ENGLISH TEXT:

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

Hi @renanc ,

If I understand your scenario correctly that when you get the data from SQL Server Database, the date column has error ?

Normally, if the date column in SQL Server is date type, it still will be the date type when loading in power bi.

For your scenario, since the date column is identified as text type when loading in Power query, I think you could use FARMAT () function to convert the text to date.

Please refer to this thread.

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you @v-piga-msft for your reply.

 

I have posted with english body here:

https://community.powerbi.com/t5/Power-Query/Error-to-convert-nvarchar-to-Datetime/m-p/792069#M26551

 

But no, this thread wont solve my issue, because it is a power query problem. 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors