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
Anonymous
Not applicable

how to create date/time/timezone field from combining date and text fields

I have the following fields:

[Date]        data type: date             setting: M/D/YYYY                               sample value: 9/1/2020

[Time]        data type: text              format: H:MM:SS AM/PM TZ              sample value: 8:05:30 AM ET

 

I need to create a derived field of type date/time/timezone in Power Query using these two fields.  How can I create this field?  For example, for the sample values above, I expect an output like:

9/1/2020 8:05:30 AM -05:00

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Go to query editor,select column "Time">"Transform">"Split column":

v-kelly-msft_0-1607653026668.png

 

And you will see:

v-kelly-msft_1-1607653039846.png

 

Then create a custom column as below:

v-kelly-msft_2-1607653099379.png

Finally you will see:

v-kelly-msft_3-1607653115848.png

 

For the M codes,see below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WstQ31DcyMDJQ0lGysDIwtTI2UHD0VXANUYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Time", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Time", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"Time.1", "Time.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Time.1", type time}, {"Time.2", type text}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.1", each DateTime.AddZone([Date]&[Time.1],-5))
in
    #"Added Custom2"

Attachment is the related .pbix file.

 

Best Regards,
Kelly

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

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Does your data exist in tables?If possible,could you pls provide a table format,not just show the field.It would be more convenient to do the data transformation.

 

Best Regards,
Kelly

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

Anonymous
Not applicable

Hi @Anonymous ,

 

Go to query editor,select column "Time">"Transform">"Split column":

v-kelly-msft_0-1607653026668.png

 

And you will see:

v-kelly-msft_1-1607653039846.png

 

Then create a custom column as below:

v-kelly-msft_2-1607653099379.png

Finally you will see:

v-kelly-msft_3-1607653115848.png

 

For the M codes,see below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WstQ31DcyMDJQ0lGysDIwtTI2UHD0VXANUYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Time = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Time", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Time", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"Time.1", "Time.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Time.1", type time}, {"Time.2", type text}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type1", "Custom.1", each DateTime.AddZone([Date]&[Time.1],-5))
in
    #"Added Custom2"

Attachment is the related .pbix file.

 

Best Regards,
Kelly

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

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