Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Calculating the difference in time where time is in the same column

I am trying to calculate the time difference between steps of a process. This process isn't always 100% clean. A step 1 can generate 4 step 2s for each step 2 they should get a step 3 and 4. I want to know per SerialNumber the difference of time between step 1 and step 2, then I want to average that. NOTE there could be cases where step 2 hasn't generated. 

I feel like I might have to transpose this into a horizontal table, but I really don't want to do that. 

 

12 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Ok, new approach:  Let's say your last step is named LastStep. I would add a new step named "SelectList". In the formula bar, type:

     

    = LastStep[TimestampID]

    Then add a new step named AddDurations, and in the formula bar, type:

     

    = Table.AddColumn(LastStep, "Durations", each if StepID > 1 then [TimestampID] - List.Max(List.Select(SelectList, each _ < [TimestampID])) else null)


    --Nate

     

     

     

     

  • Please provide sample data in usable format (not as a picture - maybe insert into a table?) and show the expected outcome.

    • Anonymous's avatar
      Anonymous
      Not applicable

      SerialNumber, StepID, ClassRecut, SerialNumber, UserID, TimestampID,

      AAD1222121M0206 AAD1222121M02168/9/2021 11:05:49 PM79
      JAC3121721M2346 JAC3121721M23518/9/2021 9:04:43 PM68
      AAD1222121M0209  68/9/2021 11:06:31 PM82
      AAD1222121M0208  68/9/2021 11:06:19 PM81
      AAD1222121M0207  68/9/2021 11:06:06 PM80
      AAD1222121M0205CC 68/9/2021 11:05:21 PM78
      AAD1222121M0204CC 68/9/2021 11:04:47 PM77
      AAD1222121M0203CC 68/9/2021 11:04:23 PM76
      AAD1222121M0202CC 68/9/2021 11:04:00 PM75
      AAD1222121M0201  68/9/2021 11:03:39 PM74
      JAC3121721M2373CC 18/18/2021 2:39:59 PM93
      JAC3121721M2372CC 18/18/2021 2:39:18 PM92
      JAC3121721M2372S 18/18/2021 2:39:05 PM91
      JAC3121721M2371  18/18/2021 2:38:07 PM90
      JAC3121721M2354CC 18/16/2021 4:38:50 PM89
      JAC3121721M2353CC 18/10/2021 2:02:29 PM88
      JAC3121721M2352U 18/10/2021 2:02:27 PM87
      JAC3121721M2352K 18/10/2021 2:02:25 PM86
      JAC3121721M2352S 18/10/2021 2:02:16 PM85
      JAC3121721M2352CC 18/10/2021 2:02:06 PM84
      JAC3121721M2351  18/10/2021 2:01:45 PM83
      JAC3121721M2362CC 18/9/2021 9:08:37 PM73
      JAC3121721M2361  18/9/2021 9:08:29 PM72
      JAC3121721M2349  18/9/2021 9:05:09 PM71
      JAC3121721M2348  18/9/2021 9:05:02 PM70
      JAC3121721M2347  18/9/2021 9:04:54 PM69
      JAC3121721M2345U 18/9/2021 9:03:47 PM67
      JAC3121721M2344S 18/9/2021 9:03:40 PM66
      JAC3121721M2345K 18/9/2021 9:03:30 PM65
      JAC3121721M2345S 18/9/2021 9:03:27 PM64
      JAC3121721M2345CC 18/9/2021 9:03:20 PM63
      JAC3121721M2344U 18/9/2021 9:03:17 PM62
      JAC3121721M2344K 18/9/2021 9:03:16 PM61
      JAC3121721M2344CC 18/9/2021 9:03:09 PM60
      JAC3121721M2343U 18/9/2021 9:03:00 PM59
      JAC3121721M2343K 18/9/2021 9:02:44 PM58
      JAC3121721M2343S 18/9/2021 9:02:35 PM57
      JAC3121721M2343CC 18/9/2021 9:02:30 PM56
      JAC3121721M2342U 18/9/2021 9:02:23 PM55
      JAC3121721M2342K 18/9/2021 9:02:14 PM54
      JAC3121721M2342S 18/9/2021 9:02:06 PM53
      JAC3121721M2342CC 18/9/2021 9:01:56 PM52
      JAC3121721M2341  18/9/2021 9:01:41 PM51
      CAW3218321M1842U 18/9/2021 4:20:45 PM50
      CAW3218321M1842K 18/9/2021 4:19:45 PM49
      CAW3218321M1842S 18/9/2021 4:19:38 PM48
      CAW3218321M1842CC 18/9/2021 4:19:28 PM47
      CAW3218321M1841  18/9/2021 4:19:08 PM46

       

      I need to turn this into this, 

       

      I can do the aggerate things easily, but the time calculations where the time is in the same row and it can branch based on the class is very complicated for me. 

       

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        Thank you for providing the sample data.

         

        You cannot have two columns with the same name.  What's the difference between columns 1 and 4?

        What's the purpose of the last column? Looks like an index (which would be fantastic)

  • Anonymous's avatar
    Anonymous
    Not applicable

    I would add an index column that starts from 1, then add:

     

    = let PriorTime = List.Max(Table.SelectRows(PriorStep, each Table.Range(_, 0, [Index]))[Timestamp]) in Table.AddColumn(PriorStep, "Durations", each if StepID > 1 then [Timestamp] - PriorTime else null)

     

    --Nate

    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User

      Keep in mind that there are different serial numbers.

      • Anonymous's avatar
        Anonymous
        Not applicable

        That being so, after adding the function, you can group by SerialNumber, and use the "Average" aggregation for the Durations column. 

        --Nate