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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How to show hour difference with decimals

Hello, I have a table in which I calculated the hour difference with the following syntax: Duration.Hours(Hour #1 - Hour #2). I get the results correctly for the integer but I can't add the decimals. I've tried to change the data type in the transform section as well as add more decimals in the Data Tools tab. All without success.

 

E.g. Hour # 1: 12:00 PM, Hour #2: 12>55 PM, result = 0.00

1 REPLY 1
adudani
Super User
Super User

hi @Anonymous ,

 

create a blank query and copy and paste the code below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0sjIwgNCmpiBmbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [task = _t, hour1 = _t, hour2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"task", Int64.Type}, {"hour1", type time}, {"hour2", type time}}),
    #"Inserted Time Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [hour1] - [hour2], type duration)
in
    #"Inserted Time Subtraction"

 

is this the desired output?

if hour 1> hour 2, would you prefer returning a 0 instead of a negative value?

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.