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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculation of Calendar time vs total time for incidents

I am working with customer incident data but my calculations are adding up all the time for every incident.

My issue is that some incidents overlap each other and share the same time frame.

Example:

Incident #1 is on 1/1/21 from 6 AM to 9 AM

Incident # 2 is on 1/1/21 from 7:30 to 10 AM

 

The incident time total is 3 hours for #1 and 2.5 hours for #2 for a total of 5.5 hours.

However, I'm looking to view downtime for all incidents without double counting the time, so really, calendar-wise, the downtime was actually 4 hours instead of 5.5.

 

Anyone working with data like this and how have you handled/displayed it?

 

Thank you.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this could meet your requirements:

Measure = 
VAR CurrentIncident_ =
    MAX ( 'Table'[Incident] )
VAR LastEnd_ =
    CALCULATE (
        MAX ( 'Table'[End DateTime] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Incident] = CurrentIncident_ - 1 )
    )
VAR ThisStart_ =
    MAX ( 'Table'[Start DateTime] )
VAR ThisEnd_ =
    MAX ( 'Table'[End DateTime] )
RETURN
    IF (
        ThisStart_ < LastEnd_,
        DIVIDE ( DATEDIFF ( LastEnd_, ThisEnd_, MINUTE ), 60 ),
        DIVIDE ( DATEDIFF ( ThisStart_, ThisEnd_, MINUTE ), 60 )
    )
Measure 2 = SUMX('Table',[Measure])

 

time.PNG

 

In addition, some blogs for reference if needed:

Find overlapping time periods using #PowerQuery - DataChant;

Find overlapping time periods using #PowerQuery - Part 2 - DataChant

 

 

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this could meet your requirements:

Measure = 
VAR CurrentIncident_ =
    MAX ( 'Table'[Incident] )
VAR LastEnd_ =
    CALCULATE (
        MAX ( 'Table'[End DateTime] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Incident] = CurrentIncident_ - 1 )
    )
VAR ThisStart_ =
    MAX ( 'Table'[Start DateTime] )
VAR ThisEnd_ =
    MAX ( 'Table'[End DateTime] )
RETURN
    IF (
        ThisStart_ < LastEnd_,
        DIVIDE ( DATEDIFF ( LastEnd_, ThisEnd_, MINUTE ), 60 ),
        DIVIDE ( DATEDIFF ( ThisStart_, ThisEnd_, MINUTE ), 60 )
    )
Measure 2 = SUMX('Table',[Measure])

 

time.PNG

 

In addition, some blogs for reference if needed:

Find overlapping time periods using #PowerQuery - DataChant;

Find overlapping time periods using #PowerQuery - Part 2 - DataChant

 

 

Best Regards,

Icey

 

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

mahoneypat
Employee
Employee

In my experience, the best way to do this is to make a disconnected table of time intervals (e.g., every 15 or 30 minutes and then iterate over that and count/add any interval that has 1 or more incidents (i.e., incidents that start before the end of the interval and end after the start of the interval).  If needed, you can then iterate over every day and for every day iterate over all the time intervals to get total incident down time.

 

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


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.