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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
FJME
Helper I
Helper I

problem in converting text format to date format in Power Query

Dear community !

I downloaded an entire table in format csv to power query and since it is in text, i changed to date format  but  errors occur in "dates" with the days in the place of month (portuguese format) as in attach. I tried different solutions (functions, column to date) in the source and in power query but the same results remain. The only "patch" was to change the format in the desktop sids (table view) but the errors persist in Power Query...

 

FJME_0-1704798514970.png

FJME_1-1704798585875.png

Thanks

 

3 ACCEPTED SOLUTIONS

I did a test with sample csv file...

id,Date
1,1/11/1990
2,1/12/1990
3,1/13/1990

 

Using the M Code below it worked fine. 

 

let
Source = Csv.Document(File.Contents("C:\Users\aliom\OneDrive\Desktop\Sample.csv"),[Delimiter=",", Columns=2, Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Inserted Parsed Date" = Table.AddColumn(#"Promoted Headers", "Parse", each Date.From(DateTimeZone.From([Date])), type date),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Parsed Date",{{"Parse", type date}})
in
#"Changed Type"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

collinsg
Super User
Super User

Hi FJME,

Here's an approach you might try. The #"Convert Date" step uses "Date.From" with the "locale" parameter "en-US". This interprets "Date" as being in the format "M/d/yyyy".

let
Source = Csv.Document(
File.Contents("C:\Users\Appin\test.csv"),
[
Delimiter = ",",
Columns = 2,
Encoding = 65001,
QuoteStyle = QuoteStyle.None
]
),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
#"Convert Date" = Table.TransformColumns(#"Promoted Headers", {{"Date", each Date.From(_, "en-US")}}),
#"Changed Type" = Table.TransformColumnTypes(#"Convert Date", {{"Date", type date}})
in
#"Changed Type"

 Hope this helps.

View solution in original post

All you should need to do is set the proper locale in the #"Changed Type" step (or whatever it is called in Portuguese.

 

The locale refers to the format of the text date. Since it seems to MDY which is a US format, you set the locale accordingly.

 

Or if you are doing this from the UI, right click on the column and select to Change Type to date using locale:

ronrsnfld_0-1704849703753.png

Then set the locale to English-United States and that should correct things.

ronrsnfld_1-1704849856235.png

 

If you are working in the Advanced Editor, add the culture argument to the #"Changed Step" step:

 

...
#"Changed Step" = Table.TransformColumnTypes(previous_step, { {"Date", type date}},"en-US")
...

View solution in original post

7 REPLIES 7
collinsg
Super User
Super User

Hi FJME,

Here's an approach you might try. The #"Convert Date" step uses "Date.From" with the "locale" parameter "en-US". This interprets "Date" as being in the format "M/d/yyyy".

let
Source = Csv.Document(
File.Contents("C:\Users\Appin\test.csv"),
[
Delimiter = ",",
Columns = 2,
Encoding = 65001,
QuoteStyle = QuoteStyle.None
]
),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
#"Convert Date" = Table.TransformColumns(#"Promoted Headers", {{"Date", each Date.From(_, "en-US")}}),
#"Changed Type" = Table.TransformColumnTypes(#"Convert Date", {{"Date", type date}})
in
#"Changed Type"

 Hope this helps.

Thanks everyone!

 

A little distraction because i tried in a first moment to change the regional settings to English (USA) that didn't appears (but Portuguese (Inglês) instead was the correct...). However the M suggestions are also correct.

regards

 

FE

amustafa
Super User
Super User

On row 13, click next to the error and paste the error here. It will show the vaule it's having a problem converting to Date.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi amustafa!

He don't accept above 12 as month...in think that is the reason. I tried regional stteings....date.value,etc without success

Regards

 

FJME_0-1704827845752.png

 

All you should need to do is set the proper locale in the #"Changed Type" step (or whatever it is called in Portuguese.

 

The locale refers to the format of the text date. Since it seems to MDY which is a US format, you set the locale accordingly.

 

Or if you are doing this from the UI, right click on the column and select to Change Type to date using locale:

ronrsnfld_0-1704849703753.png

Then set the locale to English-United States and that should correct things.

ronrsnfld_1-1704849856235.png

 

If you are working in the Advanced Editor, add the culture argument to the #"Changed Step" step:

 

...
#"Changed Step" = Table.TransformColumnTypes(previous_step, { {"Date", type date}},"en-US")
...

I did a test with sample csv file...

id,Date
1,1/11/1990
2,1/12/1990
3,1/13/1990

 

Using the M Code below it worked fine. 

 

let
Source = Csv.Document(File.Contents("C:\Users\aliom\OneDrive\Desktop\Sample.csv"),[Delimiter=",", Columns=2, Encoding=65001, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Inserted Parsed Date" = Table.AddColumn(#"Promoted Headers", "Parse", each Date.From(DateTimeZone.From([Date])), type date),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Parsed Date",{{"Parse", type date}})
in
#"Changed Type"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks a lot amustafa! I left now my daily job but tomorrow i will test in the morning and give you feedback. Regards. FE

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.