cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
ehaider
Frequent Visitor

Date and time difference excluding non business hours

Hi All, I've one query, I've two dates like start date is 10/01/2022 09:06:03 and end date is 30/01/2022 06:05:01 and I need time difference that should excludes:

- Non working Hrs like here working hrs is starts 09:00:00 and ends 17:00:00

- Weekoff Sat and Sun

- Holidays - 20/01/2022

Please help me out.

Thanks!

1 ACCEPTED SOLUTION

This is much more complex than you may expect.  You have to account for all kinds of corner cases (for example when the clock starts on a work day but before 9am or after 5pm etc).

 

Here is a sample implementation that returns the resulting day fractions.  You can multiply the sum by 24 to arrive at the hours, or leave as is and interpret as duration.

 

The sample implementation is a proof of concept - you would have to provide a couple more test intervals to see how this could look like in production.

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Where would you like to do that, in Power Query or in DAX?  Are you aware of the NETWORKDAYS() function in DAX?

You also need to define what should happen if your interval starts or ends on a non-workday  (in your example Janary 30 is a sunday). Should the hours still count or should they be ignored?

Thanks for Picking my query:

 

I've got the duration in HH:MM:SS format in Power Query with below query. but unable to calculation on Matrix Visual, However it given result in Power query.

 

HH:MM:SS - Resolution time (hrs) New =
VAR MTTR = 'Task Acceptance P1-P2-P3-P4'[Resolution time (hrs) New]
VAR Hours = TRUNC ( MTTR )
VAR MinSec = FORMAT ( MAX ( MTTR - Hours, 0 ) / 24, ":nn:ss" )
RETURN
IF ( NOT ISBLANK ( MTTR ), Hours & MinSec )

 

 it is taking zero in Matrix Visual. 

ehaider_0-1669532708853.png

 

This is much more complex than you may expect.  You have to account for all kinds of corner cases (for example when the clock starts on a work day but before 9am or after 5pm etc).

 

Here is a sample implementation that returns the resulting day fractions.  You can multiply the sum by 24 to arrive at the hours, or leave as is and interpret as duration.

 

The sample implementation is a proof of concept - you would have to provide a couple more test intervals to see how this could look like in production.

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors