Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Time difference between date time values in same column based on a value in a different column

Hello,

I am trying to aggregate the time a user has spent in the Receipt function scanning items in the warehouse. How would I get the output in the following table (elapsed seconds):

 

Assignment 1UserDate Time StartFunctionElapsed Seconds
1JF9/30/19 8:16 AMRECEIPT0
1JF9/30/19 8:17 AMRECEIPT60
2MK10/1/19 4:04 PMRECEIPT0
2MK10/1/19 4:10 PMRECEIPT0
2MK10/1/19 4:11 PMRECEIPT420

 

Essentially, I need to aggregate the elapsed seconds by User for the Receipt function. I know I need to use the DATEDIFF between the minimal date/time and max date time for the user that is completing the receipt function, but I am not sure how to have 0 for all values except for the last one (the aggregated value). I guess I could have the number of seconds between each date since power bi will aggregate it anyway. So, to have:

 

Assignment 1UserDate Time StartFunctionElapsed Seconds
1JF9/30/19 8:16 AMRECEIPT0
1JF9/30/19 8:17 AMRECEIPT60
2MK10/1/19 4:04 PMRECEIPT0
2MK10/1/19 4:10 PMRECEIPT360
2MK10/1/19 4:11 PMRECEIPT60

 

The receipt function is not the only function in the dataset, so I would need to filter to that function and aggregate the time by user.

I appreciate the help!

  • Hi Anonymous ,

    Here is the pbix PBIX 
    I put both columns in so that you have your choice, the second column only shows in the last row of the user. The difference between the measure and the column at the high level, is that with a measure, the engine does not have row context, whereas in the table it does. (It knows which row it is operating on.) Therefore it was just a matter of dropping MAX().


    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
    Nathaniel

     

11 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi Anonymous 
    What is the difference between the two tables?
    Nathaniel

    • Nathaniel_C's avatar
      Nathaniel_C
      Community Champion

      Hi Anonymous ,

      If I understand correctly this is what you are looking as an output? 
      Let me know if you have any questions.

      If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
      Nathaniel


       

       

       

      lapse Secs Calc = 
      VAR _curTime =
          MAX ( TimeElapse[Date Time Start] )
      VAR _pasttime =
          CALCULATE (
              MAX ( TimeElapse[Date Time Start] ),
              TimeElapse[Date Time Start] < _curTime,
              ALLEXCEPT ( TimeElapse, TimeElapse[User], TimeElapse[Function] )
          )
      VAR _dif =
          DATEDIFF ( _pasttime, _curTime, SECOND )
      RETURN
          _dif

       



       

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        Hi Anonymous 
        Or with zeros.
        Let me know if you have any questions.

        If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
        Nathaniel

         

        Elapse Secs Calc = 
        VAR _curTime =
            MAX ( TimeElapse[Date Time Start] )
        VAR _pasttime =
            CALCULATE (
                MAX ( TimeElapse[Date Time Start] ),
                TimeElapse[Date Time Start] < _curTime,
                ALLEXCEPT ( TimeElapse, TimeElapse[User], TimeElapse[Function] )
            )
        VAR _dif =
            IF(ISBLANK(_pasttime), 0 ,DATEDIFF ( _pasttime, _curTime, SECOND ))
        RETURN
            _dif