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! Request now

Reply
Kitu11
Frequent Visitor

Calculate the total time(Hours) difference for the status "on Hold"

Hello all,

I hope you're all doing well.

I'd like to determine the total number of hours between the instances when the status was "On Hold" and the subsequent status, as depicted in the photo attached below. As you can see, the case has been put "On Hold" multiple times. Therefore, the aim is to calculate the overall duration in hours.

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.

sample.jpeg

I have created a calendar table as well

sample 2.jpeg

Thank you so much for your help in Advance 🙂

4 REPLIES 4
vanessafvg
Super User
Super User

please provide the data in text format for your sample data.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hello,

 

Thanks for your reply
Please have a look at the attached table,

Case history table  
Case numberCurrent StatusCreated date
1234Created7/14/23 4:20 PM
1234In progress7/14/23 4:26 PM
1234on hold7/14/23 4:39 PM
1234Ready to proceed7/18/23 9:12 AM
1234Approved7/18/23 9:45 AM
1234On hold7/18/23 9:56 AM
1234Evaluation7/19/23 11:12 AM
1234Approved7/19/23 11:40 AM
1234Closed7/19/23 11:55 AM
1234Closed7/19/23 11:55 AM



Anonymous
Not applicable

Hi @Kitu11 ,

 

I suggest you to try code as below to create a measure.

Hours = 
VAR _NEXYDATE =
    CALCULATE (
        MIN ( 'Table'[Created date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Case number] ),
            'Table'[Created date] > MAX ( 'Table'[Created date] )
        )
    )
VAR _OtherDays =
    CALCULATE (
        COUNT ( 'Calendar'[Date] ),
        FILTER (
            'Calendar',
            NOT ( 'Calendar'[WeekDay] IN { 6, 7 } )
                && 'Calendar'[Date] > DATEVALUE ( MAX ( 'Table'[Created date] ) )
                && 'Calendar'[Date] < DATEVALUE ( _NEXYDATE )
        )
    )
VAR _STARTDAYHOUR =
    DATEDIFF (
        MAX ( 'Table'[Created date] ),
        DATEVALUE ( MAX ( 'Table'[Created date] ) ) + TIME ( 18, 00, 00 ),
        SECOND
    ) / 3600
VAR _ENDDAYHOUR =
    DATEDIFF ( DATEVALUE ( _NEXYDATE ) + TIME ( 8, 00, 00 ), _NEXYDATE, SECOND ) / 3600
RETURN
    IF (
        MAX ( 'Table'[Current Status] ) = "On hold",
        _STARTDAYHOUR + _OtherDays * 10 + _ENDDAYHOUR
    )

Result is as below.

vrzhoumsft_0-1690872838359.png

Best Regards,
Rico Zhou

 

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

 

Hello,
I have tried it but it didn't work : ( 
I should have given some more info

Here i have added some more info below,

 

I have two tables with one - many relationship, Case(One) and case history(Many) tables.
Case history stores the logs of each case.

I am currently using the calculated column in the Case table, 


time diff onhold(Business hours) =
Var start_ =
CALCULATE(
MAX('Case History'[Created date(Fixed)]),
'Case History'[NewValue] = "On Hold" &&
'Case History'[Field] = "Status" &&
'Case History'[OldValue] <> "On Hold"
)
Var end_ =
CALCULATE(
MAX('Case History'[Created date(Fixed)]),

'Case History'[NewValue] <> "On Hold" &&
'Case History'[OldValue] = "On Hold"
)

Return

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


 

The above code calculates only the latest time diff between the on-hold and the next status.
As shown in the photos below

 

1) This one is a table visual that consist of case number from the case table and the calculated column dax calculates the time difference
WhatsApp Image 2023-08-03 at 17.17.02.jpeg
2) This one is a case log of each case from the case history table and this is also a table visual

WhatsApp Image 2023-08-03 at 17.16.37.jpeg

 

 

Could you please help me here? 🙂

Regards
Kate

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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 Solution Authors
Top Kudoed Authors