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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
joshua1990
Post Prodigy
Post Prodigy

HHMMSS without leading Zeros to HH:MM:SS

Hi all!

I have a column that shows me the time of the day but without leading zeros:

For instance:

  • Instead of 00:00:02 it is 2
  • Instead of 02:00:30 it is 20030

 

How can I change this within power query?

 

Thanks in advance

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @joshua1990 ,

 

Add a new custom column like this:

let _time = Text.PadStart(Text.From([time]), 6, "0") in
Text.Combine(
    {
        Text.Start(_time, 2),
        Text.Middle(_time, 2, 2),
        Text.End(_time, 2)
    }, ":"
)

 

Working example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlKK1QGSBgbGBmCWsamZAYRlaWRuaghmGRoamRqbKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [time = _t]),
    chgToInteger = Table.TransformColumnTypes(Source,{{"time", Int64.Type}}),
    addTimeFormatted = Table.AddColumn(chgToInteger, "timeFormatted", each
    let
        _time = Text.PadStart(Text.From([time]), 6, "0")
    in
        Text.Combine(
            {
                Text.Start(_time, 2),
                Text.Middle(_time, 2, 2),
                Text.End(_time, 2)
            }, ":"
        )
    )
in
    addTimeFormatted

 

Example output:

BA_Pete_0-1673868978494.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi @joshua1990 ,

 

Add a new custom column like this:

let _time = Text.PadStart(Text.From([time]), 6, "0") in
Text.Combine(
    {
        Text.Start(_time, 2),
        Text.Middle(_time, 2, 2),
        Text.End(_time, 2)
    }, ":"
)

 

Working example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlKK1QGSBgbGBmCWsamZAYRlaWRuaghmGRoamRqbKMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [time = _t]),
    chgToInteger = Table.TransformColumnTypes(Source,{{"time", Int64.Type}}),
    addTimeFormatted = Table.AddColumn(chgToInteger, "timeFormatted", each
    let
        _time = Text.PadStart(Text.From([time]), 6, "0")
    in
        Text.Combine(
            {
                Text.Start(_time, 2),
                Text.Middle(_time, 2, 2),
                Text.End(_time, 2)
            }, ":"
        )
    )
in
    addTimeFormatted

 

Example output:

BA_Pete_0-1673868978494.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors