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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
cottrera
Post Prodigy
Post Prodigy

Convert time (hh:mm) to decimal

Hi

I have the following table

 

Time ReceivedTime Decimal
09:519.85
09:409.67
09:449.73
18:3718.62
16:0416.07
16:2816.47
01:301.50
08:328.53
09:349.57
12:1412.23
08:318.52
08:258.42
06:136.22
19:1119.18
10:4410.73
18:2118.35
11:1411.23

 

I wish to convert  the time field (hh:mm) into decimal.

 

thank you

 

Richard

 

1 ACCEPTED SOLUTION

nonono, you don't want to add column to column. In addition to that your [Time Received] is not text but of "time" type. That's smth new to me. Replace your "lady in red" with this:

#"Added Custom" = Table.AddColumn(#"Inserted Hour", "Time Decimal", each [a = Time.ToRecord([Time Received]), b = Number.Round(a[Hour] + a[Minute] / 60, 2)][b])

 

View solution in original post

6 REPLIES 6
cottrera
Post Prodigy
Post Prodigy

Thats got it thank you for your patience , legend 😀

cottrera
Post Prodigy
Post Prodigy

Hi AlienSx

I have added your code to my other code via the advanced editor.

 

let
Source = Exchange.Contents("xxxxxxxxxxxxxxxxxxx"),
Mail1 = Source{[Name="Mail"]}[Data],
#"Duplicated Column" = Table.DuplicateColumn(Mail1, "DateTimeReceived", "DateTimeReceived - Copy"),
#"Changed Type" = Table.TransformColumnTypes(#"Duplicated Column",{{"DateTimeReceived - Copy", type time}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"DateTimeReceived - Copy", "Time Received"}}),
#"Duplicated Column1" = Table.DuplicateColumn(#"Renamed Columns", "DateTimeReceived", "DateTimeReceived - Copy"),
#"Extracted Day Name" = Table.TransformColumns(#"Duplicated Column1", {{"DateTimeReceived - Copy", each Date.DayOfWeekName(_), type text}}),
#"Renamed Columns1" = Table.RenameColumns(#"Extracted Day Name",{{"DateTimeReceived - Copy", "Day"}}),
#"Inserted Hour" = Table.AddColumn(#"Renamed Columns1", "Hour", each Time.Hour([Time Received]), Int64.Type),
#"Added Custom" = Table.AddColumn(#"Inserted Hour", "Custom", each Table.AddColumn(Source, "Time Decimal", each [a = Time.ToRecord(Time.FromText([Time Received])), b = Number.Round(a[Hour] + a[Minute] / 60, 2)][b]))
in
#"Added Custom"


However, when I tried to expand the table

cottrera_1-1684409690036.png

 

 

I receive this message

cottrera_3-1684409747225.png

Richard

 

 

nonono, you don't want to add column to column. In addition to that your [Time Received] is not text but of "time" type. That's smth new to me. Replace your "lady in red" with this:

#"Added Custom" = Table.AddColumn(#"Inserted Hour", "Time Decimal", each [a = Time.ToRecord([Time Received]), b = Number.Round(a[Hour] + a[Minute] / 60, 2)][b])

 

AlienSx
Super User
Super User

hi, @cottrera 

[a = Time.ToRecord(Time.FromText([Time Received])), b = a[Hour] + a[Minute] / 60][b]

Hi AlienSx thankyou for responding so quickly. Im not sure I fully understadn  how to apply this logic in Power Query. Could you please expand RIchard

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY3BDcAgDAN34d1HnAQKXgWx/xpUBFB/J/uc9J6kMSONZ5HLJV+ESnuDCsUPaQ0PtL34PD1b254Sflsc0hxUCAuvEdFCfn91Z1hXxgQ=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Time Received" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Time Decimal", each [a = Time.ToRecord(Time.FromText([Time Received])), b = Number.Round(a[Hour] + a[Minute] / 60, 2)][b])
in
    #"Added Custom"

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors
Top Kudoed Authors