Calculate the time difference

Marta1

New Member
Joined
Jan 14, 2023
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
Hello all,

I hope you're all doing well.

I want to determine the total number of hours between the instances when the status was "On Hold" and the subsequent status.

Two conditions need to be considered:

1. Weekends should be excluded from the calculation.

2. Only business hours, which are from 8:00 am to 6:00 pm, should be taken into account.

I have created the calender table to acheive that, you can get the clear view in the attached PBIX file

So, the dax calculated column i mentioned below Only calculates the latest on hold time difference because of Max Function,

As you can see in the photo below, the time which was marked in a black spot was excluded but I want to also include it in the calculation.

I have attached the link to the power bi file


At this moment, I am using a calculated column
Total onhold difference(Business hours) =
Var start_ =
CALCULATE(
MAX('Case history'[Created Date]),
'Case history'[New Value] = "On Hold" &&
'Case history'[Field] = "Status"
)

Var end_ =
CALCULATE(
MAX('Case history'[Created Date]),
'Case history'[Old Value] = "On Hold" &&
'Case history'[New Value] <> "On Hold" &&
'Case history'[Field] = "Status"
)

return
SUMX(
CALCULATETABLE(
'Calendar table',
DATESBETWEEN('Calendar table'[Date],start_,end_),
'Calendar table'[weekday] = 1
),
MAX(MIN('Calendar table'[end],end_)-MAX('Calendar table'[start],start_),0)*24)

Could you please help me here?

Thank you so much in advance
 

Attachments

  • IMG_0526.png
    IMG_0526.png
    54.5 KB · Views: 10

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Take a look at my article here and see if it helps.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top