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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Difference in Hours Calculation for Duration - Negative +1 day

I have the below data, and I am trying to edit it in Power Query Editor. I wanted it to show the number of minutes between two hours - with column name - "In" and "Out" as shown in the picture. I tried it out and some of them popped as negative hours.

Since the data has only one date column and not the next day, I am not able to find out a solution.

The data has to show me 13 minutes but shows -1367 minutes

 

 
 

Untitled.png

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You can add a custom column with the formula below.  It checks if the Out is less than the In and, if so, it sums the time between Out and midnight and In and midnight.  This is in minutes so you can sub with Duration.TotalHours or just divide the result by 60.

 

= if [In] <= [Out] then Duration.TotalMinutes([Out] - [In]) else Duration.TotalMinutes(#time(24,0,0) - [In]) + Duration.TotalMinutes([Out] - #time(0,0,0))

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

You can add a custom column with the formula below.  It checks if the Out is less than the In and, if so, it sums the time between Out and midnight and In and midnight.  This is in minutes so you can sub with Duration.TotalHours or just divide the result by 60.

 

= if [In] <= [Out] then Duration.TotalMinutes([Out] - [In]) else Duration.TotalMinutes(#time(24,0,0) - [In]) + Duration.TotalMinutes([Out] - #time(0,0,0))

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat- That works great

edhans
Super User
Super User

Please post data that we can take a look at, and which two fields you are using to want to get the difference.

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors