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
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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.