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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
igonzalezb
Helper I
Helper I

Average elapsed time for a job to change hands from one worker to others

I would like to know the average time it takes for Jobs to change from Worker X to any other worker. Timestamp is here shown as an integer. The result should be (2+10)/2 = 6. See that JobID 3 hasn't changed from Worker X and should be ignored in the calculation.

 

JobIDTimestampWorker
215C
312X
18A
14B
13C
25X
12B
21A
10X

 

Using this example, the logic behind the calculation is as follows:

  1. For JobID = 1, X has the job at timestamp 0. Then JobID=1 changes worker at timestamp = 2. Therefore the time elapsed is 2.
  2. For JobID = 2, X has the job at timestamp 5. Then JobID=2 changes worker at timestamp 15.  Therefore the time elapsed is 10.
  3. For JobID = 3, X has the job at timestamp 12. This JobID hasn't changed worker since. Time elapsed is null.
  4. Average of the 3, not counting null, is (2+10)/2 = 6.

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression.  It returns 6 for your example data.  If you want a more general solution, you can replace the FILTER(__summary, Jobs[Worker] = "X") with just __summary (to use it in a table for example to see the avg time for each employee.

Avg Job Change Time =
VAR __summary =
    ADDCOLUMNS (
        SUMMARIZE ( Jobs, Jobs[Worker], Jobs[JobID], Jobs[Timestamp] ),
        "@nexttimestamp", CALCULATE (
            MIN ( Jobs[Timestamp] ),
            ALL ( Jobs ),
            Jobs[Timestamp] > EARLIER ( Jobs[Timestamp] ),
            Jobs[JobID] = EARLIER ( Jobs[JobID] )
        ) + 0
    )
RETURN
    AVERAGEX (
        FILTER ( FILTER ( __summary, Jobs[Worker] = "X" ), [@nexttimestamp] > 0 ),
        [@nexttimestamp] - Jobs[Timestamp]
    )

 

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

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression.  It returns 6 for your example data.  If you want a more general solution, you can replace the FILTER(__summary, Jobs[Worker] = "X") with just __summary (to use it in a table for example to see the avg time for each employee.

Avg Job Change Time =
VAR __summary =
    ADDCOLUMNS (
        SUMMARIZE ( Jobs, Jobs[Worker], Jobs[JobID], Jobs[Timestamp] ),
        "@nexttimestamp", CALCULATE (
            MIN ( Jobs[Timestamp] ),
            ALL ( Jobs ),
            Jobs[Timestamp] > EARLIER ( Jobs[Timestamp] ),
            Jobs[JobID] = EARLIER ( Jobs[JobID] )
        ) + 0
    )
RETURN
    AVERAGEX (
        FILTER ( FILTER ( __summary, Jobs[Worker] = "X" ), [@nexttimestamp] > 0 ),
        [@nexttimestamp] - Jobs[Timestamp]
    )

 

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


ryan_mayu
Super User
Super User

@igonzalezb 

could you please provide detailed logic on the calculation? how to get 10 and 2 in your formula?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu Please see my edit. Hope it helps. Thank you!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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