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
m0v08wo
Frequent Visitor

Calculate time spent in process excluding stages

Dear Power BI team,
I am a new person to the community and would like find the optimal way of calculating work logs.

I have a work log of ticket processing. I need to calculate total time spent per each ticket for 2 specific stages:
- Between "Submited" and "Process_Started".

- Between "Process_Started" and the very first result ("Rejected" or"Approved") but excluding "Process_Saved" in between.
Both statuses should appear for the very first time since the process is repetetative.
I would be very glad for any options. 
Thank you very much.

This is how it looks like:

m0v08wo_0-1692745150281.png

This is the raw data:

log_idticket_idAction_StartAction_EndAction_Start_TimeAction_End_TimeHours_Spent
18792123123CreateChecked1/27/2021 4:121/27/2021 4:330.34
18793123123CheckedChecked1/27/2021 4:331/27/2021 4:330.00
18794123123CheckedSubmited1/27/2021 4:331/27/2021 4:330.01
18795123123SubmitedAssigned1/27/2021 4:331/27/2021 13:539.34
18874123123AssignedProcess_Started1/27/2021 13:531/27/2021 14:520.98
18924123123Process_StartedProcess_Saved1/27/2021 14:521/27/2021 15:050.22
18930123123Process_SavedRejected1/27/2021 15:051/29/2021 16:5249.78
19900123123RejectedReviewed1/29/2021 16:521/29/2021 16:540.03
19901123123ReviewedReviewed1/29/2021 16:541/29/2021 13:171.38
19942123123ReviewedChecked1/29/2021 13:171/29/2021 13:280.18
19955123123CheckedChecked1/29/2021 13:281/29/2021 13:280.00
19956123123CheckedSubmited1/29/2021 13:281/29/2021 13:280.01
19959123123SubmitedAssigned1/29/2021 13:281/29/2021 13:410.22
19962123123AssignedProcess_Started1/29/2021 13:411/29/2021 13:420.01
19966123123Process_StartedViewed1/29/2021 13:421/29/2021 13:470.09
19968123123ViewedRejected1/29/2021 13:471/29/2021 13:480.02
19969123123RejectedChecked1/29/2021 13:481/29/2021 13:590.18
19978123123CheckedChecked1/29/2021 13:591/29/2021 13:590.00
19979123123CheckedSubmited1/29/2021 13:591/29/2021 19:000.01
19980123123SubmitedViewed1/29/2021 19:001/29/2021 19:190.33
19996123123ViewedAssigned1/29/2021 19:191/29/2021 19:200.01
19998123123AssignedProcess_Started1/29/2021 19:201/29/2021 19:200.00
19999123123Process_StartedCompleted1/29/2021 19:201/29/2021 19:200.01
20000123123CompletedReleased1/29/2021 19:201/29/2021 19:200.00
20001123123ReleasedViewed1/29/2021 19:201/29/2021 21:482.46
20038123123ViewedViewed1/29/2021 21:481/30/2021 13:3315.75
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @m0v08wo,

You can try to use the following calculate column formulas if they suitable for your requirement:

1st stages = 
IF (
    Table1[Action_Start] = "Submited",
    VAR endID =
        CALCULATE (
            MIN ( Table1[log_id] ),
            FILTER (
                Table1,
                [log_id] > EARLIER ( Table1[log_id] )
                    && Table1[Action_Start] = "Process_Started"
            )
        )
    RETURN
        CALCULATE (
            SUM ( Table1[Hours_Spent] ),
            FILTER ( Table1, [log_id] >= EARLIER ( Table1[log_id] ) && [log_id] <= endID )
        )
)

2nd stages = 
IF (
    Table1[Action_Start] = "Process_Started",
    VAR endID =
        CALCULATE (
            MIN ( Table1[log_id] ),
            FILTER (
                Table1,
                [log_id] > EARLIER ( Table1[log_id] )
                    && Table1[Action_Start] IN { "Rejected", "Approved" }
            )
        )
    RETURN
        CALCULATE (
            SUM ( Table1[Hours_Spent] ),
            FILTER (
                Table1,
                [log_id] >= EARLIER ( Table1[log_id] )
                    && [log_id] <= endID
                    && Table1[Action_Start] <> "Process_Saved"
            )
        )
)

1.png

Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @m0v08wo,

You can try to use the following calculate column formulas if they suitable for your requirement:

1st stages = 
IF (
    Table1[Action_Start] = "Submited",
    VAR endID =
        CALCULATE (
            MIN ( Table1[log_id] ),
            FILTER (
                Table1,
                [log_id] > EARLIER ( Table1[log_id] )
                    && Table1[Action_Start] = "Process_Started"
            )
        )
    RETURN
        CALCULATE (
            SUM ( Table1[Hours_Spent] ),
            FILTER ( Table1, [log_id] >= EARLIER ( Table1[log_id] ) && [log_id] <= endID )
        )
)

2nd stages = 
IF (
    Table1[Action_Start] = "Process_Started",
    VAR endID =
        CALCULATE (
            MIN ( Table1[log_id] ),
            FILTER (
                Table1,
                [log_id] > EARLIER ( Table1[log_id] )
                    && Table1[Action_Start] IN { "Rejected", "Approved" }
            )
        )
    RETURN
        CALCULATE (
            SUM ( Table1[Hours_Spent] ),
            FILTER (
                Table1,
                [log_id] >= EARLIER ( Table1[log_id] )
                    && [log_id] <= endID
                    && Table1[Action_Start] <> "Process_Saved"
            )
        )
)

1.png

Regards,

Xiaoxin Sheng

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