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

Need help in DAX to calculate "End Time" based on scenarios

Hi All, 

I need help to calculate the time worked upon by Level 1 support team. 

 

Example Dataset:

Table1 showing tracking time of teams involved for incident ID - 001 

Incident IdOwnerTeamIncident Logged Start TimeEnd Time
001zzzzzQ18/7/2020 15:008/9/2020 16:458/9/2020 17:00
001abcL18/7/2020 15:008/9/2020 17:008/9/2020 17:50
001aaaaaE18/7/2020 15:008/9/2020 17:508/9/2020 18:00
001xyzL28/7/2020 15:008/9/2020 18:008/9/2020 19:00
001abcL18/7/2020 15:008/9/2020 19:008/9/2020 19:10
001aaaaaE18/7/2020 15:008/9/2020 19:108/9/2020 20:00

 

Where - 

L1Level 1 Support
Q1 Intermediate Queue
E1Escalation Queue
L2 Level 2 Support

 

So the aim is to 

1) Calculate the "END TIME" when incident has been transferred from L1 to E1 or L2. 

2) Create a Calculated column for days between "INCIDENT LOGGED" and "END TIME". 

 

Expected Output: 

Incident IdOwnerTeamIncident Logged Start TimeEnd TimeExpected Output
001zzzzzQ18/7/2020 15:008/9/2020 16:458/9/2020 17:00Blank
001abcL18/7/2020 15:008/9/2020 17:008/9/2020 17:502 days
001aaaaaE18/7/2020 15:008/9/2020 17:508/9/2020 18:00Blank
001xyzL28/7/2020 15:008/9/2020 18:008/9/2020 19:00Blank
001abcL18/7/2020 15:008/9/2020 19:008/9/2020 19:10Blank
001aaaaaE18/7/2020 15:008/9/2020 19:108/9/2020 20:00Blank

 

Now the challenge here is the incident lifecycle can be of varying types as below - 

 

12345678
L1L1Q1Q1Q1Q1Q1Q1
 Q1L1L1L1L1L1L1
   E1L2Q1E1E1
     L1L2L2
       L1
       E1

 

Please help to develop a robust solution to handle all kinds of scenario. 

@amitchandak ,@Greg_Deckler  - Please assist. 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Anonymous 

I build a table like yours and add an index column in Power Query Editor to have a test.

1.png

From your statement I think you want to calculate the differences between Incident Logged and End Time by day, if Team is changing from L1 to E1 or L2. But your example make me confused, the Expected Output in the red box should be 2 rather than blank. If there is anything wrong in my understanding, please tell me.

2.png

My measure:

 

Measure = 
VAR _Team =
    MAX ( 'Table'[Team] )
VAR _Datediff =
    DATEDIFF ( MAX ( 'Table'[Incident Logged ] ), MAX ( 'Table'[End Time] ), DAY )
VAR _NextTeam =
    CALCULATE (
        MAX ( 'Table'[Team] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = MAX ( 'Table'[Index] ) + 1 )
    )
RETURN
    IF (
        AND ( _Team = "L1", OR ( _NextTeam = "E1", _NextTeam = "L2" ) ),
        _Datediff,
        BLANK ()
    )

 

 Result:

3.png

If this reply still couldn't help you solve your problem, please tell me more details such as your calculate logic and why the L1 in red box is unqualified. Or you can share your pbix file with me by your OneDrive for Business.

You can download the pbix file from this link: Need help in DAX to calculate "End Time" based on scenarios

 

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. 

View solution in original post

mahoneypat
Microsoft Employee
Microsoft Employee

Please try these two column expressions, replacing Incidents with your actual table name. 

 

Overall End Time =
VAR firstE1L2 =
    CALCULATE (
        MIN ( Incidents[Start Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] IN { "E1", "L2" }
    )
VAR lastL1 =
    CALCULATE (
        MAX ( Incidents[End Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] = "L1",
        Incidents[End Time] <= firstE1L2
    )
VAR minL1 =
    CALCULATE (
        MIN ( Incidents[Start Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] = "L1"
    )
RETURN
    IF ( AND ( Incidents[Start Time] = minL1, Incidents[Team] = "L1" ), lastL1 )


Days = if(not(ISBLANK(Incidents[Overall End Time])), Incidents[Overall End Time] - Incidents[Incident Logged ])

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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

9 REPLIES 9
Anonymous
Not applicable

Thank you all for assistance, I am still testing the solution for all use cases we have. I will update soon. 

Anonymous
Not applicable

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

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. 

mahoneypat
Microsoft Employee
Microsoft Employee

Please try these two column expressions, replacing Incidents with your actual table name. 

 

Overall End Time =
VAR firstE1L2 =
    CALCULATE (
        MIN ( Incidents[Start Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] IN { "E1", "L2" }
    )
VAR lastL1 =
    CALCULATE (
        MAX ( Incidents[End Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] = "L1",
        Incidents[End Time] <= firstE1L2
    )
VAR minL1 =
    CALCULATE (
        MIN ( Incidents[Start Time] ),
        ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
        Incidents[Team] = "L1"
    )
RETURN
    IF ( AND ( Incidents[Start Time] = minL1, Incidents[Team] = "L1" ), lastL1 )


Days = if(not(ISBLANK(Incidents[Overall End Time])), Incidents[Overall End Time] - Incidents[Incident Logged ])

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

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

Hey Pat, 

 

Thank you for the solution, it helped me to a greater extent. To make it fit in all below scenarios - 

12345678
L1L1Q1Q1Q1Q1Q1Q1
 Q1L1L1L1L1L1L1
   E1L2Q1E1E1
     L1L2L2
       L1
       E1

 

I have modified the calculation as - 

Overall End Time =
VAR firstE1L2 =
CALCULATE (
MIN ( Incidents[Start Time] ),
ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
Incidents[Team] IN { "E1", "L2" }
)
VAR lastL1 =
CALCULATE (
MAX ( Incidents[End Time] ),
ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
Incidents[Team] = "L1",
Incidents[End Time] <= firstE1L2
)

VAR maxL1 =
CALCULATE (
MAX ( Incidents[End Time] ),
ALLEXCEPT ( Incidents, Incidents[Incident Id] ),
Incidents[Team] = "L1"
)

var endTime = if(ISBLANK(firstE1L2),maxL1,lastL1)

RETURN
IF ( AND ( Incidents[End Time] = endTime, Incidents[Team] = "L1" ), endTime )

Anonymous
Not applicable

Hi @Anonymous 

I build a table like yours and add an index column in Power Query Editor to have a test.

1.png

From your statement I think you want to calculate the differences between Incident Logged and End Time by day, if Team is changing from L1 to E1 or L2. But your example make me confused, the Expected Output in the red box should be 2 rather than blank. If there is anything wrong in my understanding, please tell me.

2.png

My measure:

 

Measure = 
VAR _Team =
    MAX ( 'Table'[Team] )
VAR _Datediff =
    DATEDIFF ( MAX ( 'Table'[Incident Logged ] ), MAX ( 'Table'[End Time] ), DAY )
VAR _NextTeam =
    CALCULATE (
        MAX ( 'Table'[Team] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = MAX ( 'Table'[Index] ) + 1 )
    )
RETURN
    IF (
        AND ( _Team = "L1", OR ( _NextTeam = "E1", _NextTeam = "L2" ) ),
        _Datediff,
        BLANK ()
    )

 

 Result:

3.png

If this reply still couldn't help you solve your problem, please tell me more details such as your calculate logic and why the L1 in red box is unqualified. Or you can share your pbix file with me by your OneDrive for Business.

You can download the pbix file from this link: Need help in DAX to calculate "End Time" based on scenarios

 

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. 

Greg_Deckler
Community Champion
Community Champion

@Anonymous - If I understand things correctly, you are looking for the difference in date/time between rows based upon specific criteria. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler for your reply. I am looking at the post you have redirected. I wil get back to you soon on this. 

mahoneypat
Microsoft Employee
Microsoft Employee

Your example data only has rows for Incident 1, but your expected output shows blank for incident 1.  Does that incident meet the criteria for going from L1 to E1 or L2?  Can you highlight/specify the values that should be used to get the proposed column?

 

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 - Thanks for highlighting, I made a mistake posting the expected output. All rows should only be for "001". I have edited the post. 

 

In the example, you see it is forwarded from L1 to E1, so the "END TIME" corresponding to L1 should be considered. 

 

001abcL1Incident Logged - 8/7/2020 15:00 8/9/2020 17:00End Time - 8/9/2020 17:50    2 days  

 

The reason it should be returning blank for other rows is report should reflect L1 efficiency. And while calculating average, blank is not considered. 

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