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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
RAKESH1986
Helper II
Helper II

Calculate two Time Column Difference in hours IN NEW COLUMN

Hi All,

 

I have these two-time columns and I want to calculate the total hour's difference In the new custom column. 

 

I took the difference but values are coming in minus. pls, help me to fix this.

i also need to take the difference of hours spent- required hours (9.6). could u tell me how to do this?

 

my table name here is timesheet.

RAKESH1986_0-1674801009684.png

 

2 ACCEPTED SOLUTIONS
RAKESH1986
Helper II
Helper II

@raimon  thanks for the help. It's working fine. could you tell me what changes I have to make to get the output like this  9.6, 10.12, 10.30 as hours difference, currently I am getting a whole number.

 

RAKESH1986_0-1674812784793.png

 

View solution in original post

Hi , @RAKESH1986 

You can try to use this M code:

Duration.Hours([Time Out]-[Time in])+ Duration.Minutes([Time Out]-[Time in])/60

vyueyunzhmsft_0-1675050730990.png

The result is as follows:

vyueyunzhmsft_1-1675050747977.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
RAKESH1986
Helper II
Helper II

@raimon  thanks for the help. It's working fine. could you tell me what changes I have to make to get the output like this  9.6, 10.12, 10.30 as hours difference, currently I am getting a whole number.

 

RAKESH1986_0-1674812784793.png

 

Hi , @RAKESH1986 

You can try to use this M code:

Duration.Hours([Time Out]-[Time in])+ Duration.Minutes([Time Out]-[Time in])/60

vyueyunzhmsft_0-1675050730990.png

The result is as follows:

vyueyunzhmsft_1-1675050747977.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

raimon
Resolver II
Resolver II

Hi @RAKESH1986,

 

while calculating the difference add this function which will convert it into hours - 

Duration.Hours([Time Out]-[Time In])

 

See below for reference - 

raimon_0-1674803072780.png

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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