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
Butters
Frequent Visitor

I have a mix of both US and UK dates in the same column

I have a mix of both US and UK dates in the same column.  I need to figure out how to get them all into the US format.  When I try to change the type to US, all of the UK dates show up as "error".  Here is a screenshot of the column I am trying to fix.  My US dates have the format MM/DD/YYYY, my UK have the format DD-MM-YYYY (i.e. slashes for US and hyphens for UK).  Need some help with this one.

Butters_0-1661789882563.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like the attached file.

Please check the below attached pbix file and the code that is used in Power Query Editor.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSN9Q3MjAyUorViVYyNtQ1MNSFc03wyBmZonANLVG5hrooPGSDUEw1MkfoiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date of SW" = _t]),
    Custom1 = Table.AddColumn(Source, "Result column", each if Text.Contains([Date of SW],"/") then 
 "en-US" else 
"en-GB"),
    #"Added Index" = Table.AddIndexColumn(Custom1, "Index", 1, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[#"Result column"]), "Result column", "Date of SW"),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Pivoted Column", {{"en-US", type date}}, "en-US"),
    #"Changed Type with Locale1" = Table.TransformColumnTypes(#"Changed Type with Locale", {{"en-GB", type date}}, "en-GB"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type with Locale1", {"Index"}, "Attribute", "Result"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Result"})
in
    #"Removed Other Columns"

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like the attached file.

Please check the below attached pbix file and the code that is used in Power Query Editor.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSN9Q3MjAyUorViVYyNtQ1MNSFc03wyBmZonANLVG5hrooPGSDUEw1MkfoiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date of SW" = _t]),
    Custom1 = Table.AddColumn(Source, "Result column", each if Text.Contains([Date of SW],"/") then 
 "en-US" else 
"en-GB"),
    #"Added Index" = Table.AddIndexColumn(Custom1, "Index", 1, 1, Int64.Type),
    #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[#"Result column"]), "Result column", "Date of SW"),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Pivoted Column", {{"en-US", type date}}, "en-US"),
    #"Changed Type with Locale1" = Table.TransformColumnTypes(#"Changed Type with Locale", {{"en-GB", type date}}, "en-GB"),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type with Locale1", {"Index"}, "Attribute", "Result"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Result"})
in
    #"Removed Other Columns"

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Worked perfectly.  Thank you so much!!

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! Prices go up Feb. 11th.

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.

Jan NL Carousel

Fabric Community Update - January 2025

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