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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
amirghaderi
Helper IV
Helper IV

Mix of US/Uk Date/ Date Time data

I have a data which is the mix of US/UK Date and Date/ Time format. Any idea how I can get all get stored as date format?

 

21/05/2020
21/10/2019
26/02/2020
21/10/2019
2/08/2022
27/07/2022
2/08/2021
24/07/2022
29/10/2021
30/09/2021
7/12/2021
23/05/2022
23/11/2021
24/07/2021
28/05/2022
17/10/2021
3/21/2022 7:54:00 AM
17/07/2021
21/11/2021
4/10/2023 8:19:00 AM
3/21/2022 8:00:00 AM
3/21/2022 8:00:00 AM
3/21/2022 8:00:00 AM
8/2/2022 4:30:00 PM
7/20/2022 4:30:00 PM
6/1/2022 11:30:00 PM
4/9/2022 4:30:00 PM
7/25/2022 4:30:00 PM
4/8/2022 4:30:00 PM
5/30/2022 9:30:00 PM
6/16/2022 4:24:00 PM
1 ACCEPTED SOLUTION

Hi @amirghaderi,

 

I trust this will resolve it for you, copy the full script into a new blank query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZBJDsMgDEWvgrKu5AEz7nKASN1Huf81SsEooJJVl+8/+xtxnhsToANGxu16VSQsSKmhB+RnCxi/khsFwDCgSmoks0ytSK1FwHRjAOJh1eoLuSPRolgxTsMU5jvAdZVNyE4yotmPPje10HRDtMSamCkNa3dfLOlfovxVyyXbmr8P/QvGpfCgRUSzEEhPTW4pBOIyd2D1dPo57fsGSxfXBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    SetDateType = Table.TransformColumns( Source,
        {
            {"Date", each 
                [ 
                    d = Splitter.SplitTextByWhitespace()(_), 
                    r = try if Text.Length( d{2}?? "" ) >1 then Date.FromText( d{0}, [Culture="en-US"]) else null 
                        otherwise Date.FromText( d{0}, [Culture="en-GB"])
                ][r], type date
            }
        })
in
    SetDateType

 

The code above is splitting the date value and sees if there is a third list item (meaning: AM, PM)

if so it converts to en-US else en-GB

 

Ps. If this helps solve your query please mark this post as Solution, thanks!

View solution in original post

3 REPLIES 3
m_dekorte
Super User
Super User

Hi @amirghaderi,

 

Sure there are ways to transform this into proper dates but does each record also contain a field from which you can deduct it's origin (UK or US)? If not, how do you plan to deal with dates that can convert both ways for example: 1/2/2022 should that be Jan 2nd or Feb 1st? 

Anything with AM/PM has USformat and anything without AM/PM has UK format. 

Hi @amirghaderi,

 

I trust this will resolve it for you, copy the full script into a new blank query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZBJDsMgDEWvgrKu5AEz7nKASN1Huf81SsEooJJVl+8/+xtxnhsToANGxu16VSQsSKmhB+RnCxi/khsFwDCgSmoks0ytSK1FwHRjAOJh1eoLuSPRolgxTsMU5jvAdZVNyE4yotmPPje10HRDtMSamCkNa3dfLOlfovxVyyXbmr8P/QvGpfCgRUSzEEhPTW4pBOIyd2D1dPo57fsGSxfXBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    SetDateType = Table.TransformColumns( Source,
        {
            {"Date", each 
                [ 
                    d = Splitter.SplitTextByWhitespace()(_), 
                    r = try if Text.Length( d{2}?? "" ) >1 then Date.FromText( d{0}, [Culture="en-US"]) else null 
                        otherwise Date.FromText( d{0}, [Culture="en-GB"])
                ][r], type date
            }
        })
in
    SetDateType

 

The code above is splitting the date value and sees if there is a third list item (meaning: AM, PM)

if so it converts to en-US else en-GB

 

Ps. If this helps solve your query please mark this post as Solution, thanks!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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