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
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
Employee
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
Employee
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
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.