Power Query number conversion to hh:mm

iosiflupis

New Member
Joined
Jan 26, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I am working in PQ to transform over 40 .csv files to excel. One of the steps that I am trying to accomplish is to convert a whole number, of up to 4 digits, to a time in hh:mm format. I have looked high and low in google search and cannot find anything that comes close.

I have tried the "ChangeType" function and all I get is ERROR. I believe that this will be a multi-step process as I will have to change all numbers to have leading zeros, and then somehow change the format to a "time" format. In the picture, you can see that I will have to do this four times total.

Thank you for your assistance.

Joseph time conversion photo.png
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Maybe something like:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}}),
    #"Split Column by Position" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type", {{"Column1", type text}}, "en-ZA"), "Column1", Splitter.SplitTextByPositions({0, 2}, true), {"Column1.1", "Column1.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Column1.1", Int64.Type}, {"Column1.2", Int64.Type}}),
    #"Inserted Literal" = Table.AddColumn(#"Changed Type1", "Literal", each ":", type text),
    #"Reordered Columns" = Table.ReorderColumns(#"Inserted Literal",{"Column1.1", "Literal", "Column1.2"}),
    #"Inserted Merged Column" = Table.AddColumn(#"Reordered Columns", "Merged", each Text.Combine({Text.From([Column1.1], "en-ZA"), [Literal], Text.From([Column1.2], "en-ZA")}, ""), type text),
    #"Inserted Parsed Time" = Table.AddColumn(#"Inserted Merged Column", "Parse", each Time.From(DateTimeZone.From([Merged])), type time)
in
    #"Inserted Parsed Time"
 
Upvote 0
Solution
I just did this on a single column on a test sheet... (could not copy your data from a picture)

What I did is I split the column by position (2 positions from right).

This then gave me two columns of where I inserted a new column with ":"....

I then merged the column to give for instance "10:11"... (delimiter was no spaces)

I then changed the data type to Time Only....
 
Upvote 0
another example

Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjMyUIrViVYyNDcxBTOMjA2hDAMIDSRjAQ==", BinaryEncoding.Base64), Compression.Deflate)), 
                let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
                
    tbl = Table.TransformColumns(Source, {{"Column1", each let t = Text.PadStart(Text.From(_),4,"0") in Time.From(Text.Start(t,2) & ":" & Text.End(t, 2))}})
in
    tbl
 
Upvote 0
Jimmypop and JGordon11,

Thank you both for the answers. I will get on them as soon as I get back to the data.
 
Upvote 0

Forum statistics

Threads
1,215,361
Messages
6,124,500
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top