Forum Discussion

rsimpson318's avatar
rsimpson318
Frequent Visitor
4 years ago
Solved

Calculate Route Stop Based on Distance/Duration

Hello,

 

I'm trying to figure out a DAX or calculated column to determine a route stop based on the duration and distance traveled (or not). I have a table with a list of points and the time each point was received. I was able to calculate the approximate distance between each point and the duration.

 

I would like to be able to determine when the vehicle is stationary and when it moves again. It could be stationary several times throughout the day and the duration can flucuate. Below is an example data set. Any help would be greatly appreciated.

 

OperatorLatitudeLongitudeDate/TimeTimeReceivedDistanceDuration
Driver 1Lat1Long14/29/2022 7:22:46 AM4/29/2022 7:22:47 AM0.000:00:20
Driver 2Lat1Long14/29/2022 7:23:06 AM4/29/2022 7:23:07 AM0.000:00:20
Driver 3Lat1Long14/29/2022 7:23:26 AM4/29/2022 7:23:27 AM0.000:00:20
Driver 4Lat1Long14/29/2022 7:23:46 AM4/29/2022 7:23:47 AM0.000:00:20
Driver 5Lat1Long14/29/2022 7:24:06 AM4/29/2022 7:24:07 AM0.000:00:20
Driver 6Lat1Long14/29/2022 7:24:26 AM4/29/2022 7:24:27 AM0.000:00:20
Driver 7Lat1Long14/29/2022 7:24:46 AM4/29/2022 7:24:47 AM0.000:00:20
Driver 8Lat1Long14/29/2022 7:25:06 AM4/29/2022 7:25:07 AM0.000:00:20
Driver 9Lat1Long14/29/2022 7:25:26 AM4/29/2022 7:25:27 AM0.000:00:20
Driver 10Lat1Long14/29/2022 7:25:46 AM4/29/2022 7:25:47 AM0.000:00:20
Driver 11Lat2Long24/29/2022 7:26:06 AM4/29/2022 7:26:07 AM0.010:00:21
Driver 12Lat3Long34/29/2022 7:26:27 AM4/29/2022 7:26:27 AM0.060:00:20
Driver 13Lat4Long44/29/2022 7:26:47 AM4/29/2022 7:26:47 AM0.050:00:19
Driver 14Lat5Long54/29/2022 7:27:06 AM4/29/2022 7:27:07 AM0.000:00:20
Driver 15Lat6Long64/29/2022 7:27:26 AM4/29/2022 7:27:27 AM0.000:00:21
Driver 16Lat7Long74/29/2022 7:27:47 AM4/29/2022 7:27:47 AM0.140:00:20
Driver 17Lat8Long84/29/2022 7:28:07 AM4/29/2022 7:28:07 AM0.180:00:20
Driver 18Lat9Long94/29/2022 7:28:27 AM4/29/2022 7:28:27 AM0.170:00:20
Driver 19Lat10Long104/29/2022 7:28:47 AM4/29/2022 7:28:47 AM0.020:00:20
Driver 20Lat11Long114/29/2022 7:29:07 AM4/29/2022 7:29:07 AM0.020:00:19
Driver 21Lat12Long124/29/2022 7:29:26 AM4/29/2022 7:29:27 AM0.000:00:20
Driver 22Lat13Long134/29/2022 7:29:46 AM4/29/2022 7:29:47 AM0.040:00:20
Driver 23Lat14Long144/29/2022 7:30:06 AM4/29/2022 7:30:07 AM0.350:00:20
Driver 24Lat15Long154/29/2022 7:30:26 AM4/29/2022 7:30:27 AM0.370:00:20
Driver 25Lat16Long164/29/2022 7:30:46 AM4/29/2022 7:30:47 AM0.210:00:21
Driver 26Lat17Long174/29/2022 7:31:07 AM4/29/2022 7:31:07 AM0.000:00:19
Driver 27Lat18Long184/29/2022 7:31:26 AM4/29/2022 7:31:27 AM0.000:00:20
Driver 28Lat19Long194/29/2022 7:31:46 AM4/29/2022 7:31:47 AM0.000:00:20
Driver 29Lat20Long204/29/2022 7:32:06 AM4/29/2022 7:32:07 AM0.010:00:21
Driver 30Lat21Long214/29/2022 7:32:27 AM4/29/2022 7:32:27 AM0.070:00:20
Driver 31Lat22Long224/29/2022 7:32:47 AM4/29/2022 7:32:47 AM0.140:00:20
Driver 32Lat23Long234/29/2022 7:33:07 AM4/29/2022 7:33:07 AM0.170:00:20
Driver 33Lat24Long244/29/2022 7:33:27 AM4/29/2022 7:33:27 AM0.220:00:20
Driver 34Lat25Long254/29/2022 7:33:47 AM4/29/2022 7:33:47 AM0.190:00:20
Driver 35Lat26Long264/29/2022 7:34:07 AM4/29/2022 7:34:07 AM0.150:00:20
Driver 36Lat27Long274/29/2022 7:34:27 AM4/29/2022 7:34:27 AM0.090:00:20
Driver 37Lat28Long284/29/2022 7:34:47 AM4/29/2022 7:34:47 AM0.010:00:20
Driver 38Lat29Long294/29/2022 7:35:07 AM4/29/2022 7:35:07 AM0.160:00:20
Driver 39Lat30Long304/29/2022 7:35:27 AM4/29/2022 7:35:27 AM0.080:00:20
Driver 40Lat31Long314/29/2022 7:35:47 AM4/29/2022 7:35:47 AM0.160:00:20
Driver 41Lat32Long324/29/2022 7:36:07 AM4/29/2022 7:36:07 AM0.170:00:19
Driver 42Lat33Long334/29/2022 7:36:26 AM4/29/2022 7:36:27 AM0.050:00:21
Driver 43Lat34Long344/29/2022 7:36:47 AM4/29/2022 7:36:47 AM0.010:00:20
Driver 44Lat35Long354/29/2022 7:37:07 AM4/29/2022 7:37:07 AM0.000:00:20
Driver 45Lat35Long354/29/2022 7:37:27 AM4/29/2022 7:37:27 AM0.000:00:19
Driver 46Lat35Long354/29/2022 7:37:46 AM4/29/2022 7:37:47 AM0.000:00:21
Driver 47Lat35Long354/29/2022 7:38:07 AM4/29/2022 7:38:07 AM0.000:00:20
Driver 48Lat35Long354/29/2022 7:38:27 AM4/29/2022 7:38:27 AM0.000:00:20
Driver 49Lat35Long354/29/2022 7:38:47 AM4/29/2022 7:38:47 AM0.000:00:19
Driver 50Lat35Long354/29/2022 7:39:06 AM4/29/2022 7:39:07 AM0.000:00:21
Driver 51Lat35Long354/29/2022 7:39:27 AM4/29/2022 7:39:27 AM0.000:00:20
Driver 52Lat35Long354/29/2022 7:39:47 AM4/29/2022 7:39:47 AM0.000:00:20
Driver 53Lat35Long354/29/2022 7:40:07 AM4/29/2022 7:40:07 AM0.000:00:20
Driver 54Lat35Long354/29/2022 7:40:27 AM4/29/2022 7:40:27 AM0.000:00:19
Driver 55Lat35Long354/29/2022 7:40:46 AM4/29/2022 7:40:47 AM0.000:00:20
Driver 56Lat35Long354/29/2022 7:41:06 AM4/29/2022 7:41:07 AM0.000:00:21
Driver 57Lat35Long354/29/2022 7:41:27 AM4/29/2022 7:41:27 AM0.000:00:20
Driver 58Lat35Long354/29/2022 7:41:47 AM4/29/2022 7:41:47 AM0.000:00:19
Driver 59Lat35Long354/29/2022 7:42:06 AM4/29/2022 7:42:07 AM0.000:00:21
Driver 60Lat35Long354/29/2022 7:42:27 AM4/29/2022 7:42:27 AM0.000:00:20
Driver 61Lat35Long354/29/2022 7:42:47 AM4/29/2022 7:42:47 AM0.000:00:19
Driver 62Lat35Long354/29/2022 7:43:06 AM4/29/2022 7:43:07 AM0.000:00:21
Driver 63Lat35Long354/29/2022 7:43:27 AM4/29/2022 7:43:27 AM0.000:00:20
Driver 64Lat35Long354/29/2022 7:43:47 AM4/29/2022 7:43:47 AM0.000:00:19
Driver 65Lat35Long354/29/2022 7:44:06 AM4/29/2022 7:44:07 AM0.000:00:21
Driver 66Lat35Long354/29/2022 7:44:27 AM4/29/2022 7:44:27 AM0.000:00:20
Driver 67Lat35Long354/29/2022 7:44:47 AM4/29/2022 7:44:47 AM0.000:00:20
Driver 68Lat35Long354/29/2022 7:45:07 AM4/29/2022 7:45:07 AM0.000:00:20
Driver 69Lat35Long354/29/2022 7:45:27 AM4/29/2022 7:45:27 AM0.000:00:20
Driver 70Lat35Long354/29/2022 7:45:47 AM4/29/2022 7:45:47 AM0.000:00:20
Driver 71Lat35Long354/29/2022 7:46:07 AM4/29/2022 7:46:07 AM0.000:00:20
Driver 72Lat35Long354/29/2022 7:46:27 AM4/29/2022 7:46:27 AM0.000:00:20
Driver 73Lat35Long354/29/2022 7:46:47 AM4/29/2022 7:46:47 AM0.000:00:19
Driver 74Lat35Long354/29/2022 7:47:06 AM4/29/2022 7:47:07 AM0.000:00:20
  • tamerj1's avatar
    tamerj1
    4 years ago

    rsimpson318 
    Hello agian
    I had some free time to do work on it. Here is a sample file folr your reference https://we.tl/t-WjszOERm4s
    My proposed solution involves adding calculated columns:

    Start Time = 
    VAR CurrentDistance =
        Routes[Distance]
    VAR LocationTable =
        CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Latitude], Routes[Longitude] ) )
    RETURN
    IF ( 
        CurrentDistance = 0 && COUNTROWS ( LocationTable ) > 1,
        MINX ( 
            LocationTable,
            Routes[Date/Time] 
        )
    )
    End Time = 
    VAR CurrentDistance =
        Routes[Distance]
    VAR LocationTable =
        CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Latitude], Routes[Longitude] ) )
    RETURN
    IF ( 
        CurrentDistance = 0 && COUNTROWS ( LocationTable ) > 1,
        MAXX ( 
            LocationTable,
            Routes[Date/Time] 
        )
    )
    Stop = 
    VAR StopNumber =
        RANKX ( FILTER ( Routes, NOT ISBLANK ( Routes[Start Time] ) ), Routes[Start Time],, ASC, Dense )
    RETURN
        IF ( 
            NOT ISBLANK ( Routes[Start Time] ),
            "Stop - " & StopNumber
        )

    Then the measure would be

    Stop Duration = 
    VAR Duration =  
        DATEDIFF ( MAX ( Routes[Start Time] ), MAX ( Routes[End Time] ), SECOND )
    RETURN
        QUOTIENT ( Duration, 60 ) & "Min and " & MOD ( Duration, 60 ) & " Sec"

    One last step would be to filter the table in order to remove the blank row

    The report looks like this

    I hope this satisfies your requirement.

14 Replies

    • rsimpson318's avatar
      rsimpson318
      Frequent Visitor

      tamerj1 

      It would either be another table or even a card that would show something like:

      StopStart TimeEnd TimeDuration
      1st Stop4/29/2022 7:22:46 AM4/29/2022 7:26:07 AM3min20sec
      2nd Stop4/29/2022 7:37:07 AM4/29/2022 7:47:07 AM10min0sec

       

      The formatting doesn't need to be exact. Let me know if this helps or you need more info.

       

      Thank you.

      • tamerj1's avatar
        tamerj1
        Community Champion

        rsimpson318 
        Hello agian
        I had some free time to do work on it. Here is a sample file folr your reference https://we.tl/t-WjszOERm4s
        My proposed solution involves adding calculated columns:

        Start Time = 
        VAR CurrentDistance =
            Routes[Distance]
        VAR LocationTable =
            CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Latitude], Routes[Longitude] ) )
        RETURN
        IF ( 
            CurrentDistance = 0 && COUNTROWS ( LocationTable ) > 1,
            MINX ( 
                LocationTable,
                Routes[Date/Time] 
            )
        )
        End Time = 
        VAR CurrentDistance =
            Routes[Distance]
        VAR LocationTable =
            CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Latitude], Routes[Longitude] ) )
        RETURN
        IF ( 
            CurrentDistance = 0 && COUNTROWS ( LocationTable ) > 1,
            MAXX ( 
                LocationTable,
                Routes[Date/Time] 
            )
        )
        Stop = 
        VAR StopNumber =
            RANKX ( FILTER ( Routes, NOT ISBLANK ( Routes[Start Time] ) ), Routes[Start Time],, ASC, Dense )
        RETURN
            IF ( 
                NOT ISBLANK ( Routes[Start Time] ),
                "Stop - " & StopNumber
            )

        Then the measure would be

        Stop Duration = 
        VAR Duration =  
            DATEDIFF ( MAX ( Routes[Start Time] ), MAX ( Routes[End Time] ), SECOND )
        RETURN
            QUOTIENT ( Duration, 60 ) & "Min and " & MOD ( Duration, 60 ) & " Sec"

        One last step would be to filter the table in order to remove the blank row

        The report looks like this

        I hope this satisfies your requirement.

  • Hi rsimpson318 ,

    Is your problem solved?? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.
    Best Regards,
    Community Support Team _ kalyj

     

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi rsimpson318 
    You did not reply to my question. Not sure if you are still interested in the solution. Anyway, please refer to the sample file with the updated solution https://we.tl/t-so64yQQdvX

    I started with grouping latitude and longitude in one column for the ease of calculation

     

    Location = Routes[Latitude] & " : " & Routes[Longitude]

     

    As the location keeps changing despite the vehicle is considered not moving, then the location need to be updated to accommodate with our our moving/stopping criteria 

     

    Adjusted Location = 
    IF ( 
        Routes[Distance] <= 0.06,
        VAR PreviousTable = FILTER ( Routes, Routes[Date/Time] < EARLIER ( Routes[Date/Time] ) )
        VAR PreviousStopTable = FILTER ( PreviousTable, Routes[Distance] <= 0.06 )
        VAR PreviousMoveTable = FILTER ( PreviousTable, Routes[Distance] > 0.06 )
        VAR EarliestStopTime = MINX ( PreviousStopTable, Routes[Date/Time] )
        VAR EarliestStopLocation = MINX ( FILTER ( PreviousStopTable, Routes[Date/Time] = EarliestStopTime ), Routes[Location] )
        VAR EarlierStopTime = MAXX ( PreviousStopTable, Routes[Date/Time] )
        VAR EarlierStopLocation = MAXX ( FILTER ( PreviousStopTable, Routes[Date/Time] = EarlierStopTime ), Routes[Location] )
        VAR EarlierMoveTime = MAXX ( PreviousMoveTable, Routes[Date/Time] )
        VAR CurrentStopTime = MAXX ( FILTER ( PreviousMoveTable, Routes[Date/Time] < EarlierMoveTime ), Routes[Date/Time] )
        VAR CurrentStopLocation = MAXX ( FILTER ( PreviousMoveTable, Routes[Date/Time] = CurrentStopTime ), Routes[Location] )
        RETURN
            COALESCE ( IF ( ISBLANK ( EarlierMoveTime ), EarliestStopLocation, CurrentStopLocation ), Routes[Location] )
    )

     

    Start and end times for each stop are calculated

     

    Start Time = 
    VAR CurrentDistance =
        Routes[Distance]
    VAR LocationTable =
        CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Adjusted Location] ) )
    RETURN
    IF ( 
        CurrentDistance <= 0.06 && COUNTROWS ( LocationTable ) > 1,
        MINX ( 
            LocationTable,
            Routes[Date/Time] 
        )
    )
    End Time = 
    VAR CurrentDistance =
        Routes[Distance]
    VAR LocationTable =
        CALCULATETABLE ( Routes, ALLEXCEPT ( Routes, Routes[Adjusted Location] ) )
    RETURN
    IF ( 
        CurrentDistance <= 0.06 && COUNTROWS ( LocationTable ) > 1,
        MAXX ( 
            LocationTable,
            Routes[Date/Time] 
        )
    )

     

    Then the stops 

     

    Stop = 
    VAR StopNumber =
        RANKX ( FILTER ( Routes, NOT ISBLANK ( Routes[Start Time] ) ), Routes[Start Time],, ASC, Dense )
    RETURN
        IF ( 
            NOT ISBLANK ( Routes[Start Time] ),
            "Stop - " & StopNumber
        )

     

     Finally the measur 

    Stop Duration = 
    VAR Duration =  
        DATEDIFF ( MAX ( Routes[Start Time] ), MAX ( Routes[End Time] ), SECOND )
    RETURN
        QUOTIENT ( Duration, 60 ) & "Min and " & MOD ( Duration, 60 ) & " Sec"

    • rsimpson318's avatar
      rsimpson318
      Frequent Visitor

      Good morning tamerj1.

       

      I apologize for the late responses. I am still interested in a solution and I'll try this out today and see how the data looks with it.

       

      To answer your question regarding "extended period": I wouldn't need to capture small periods where they aren't moving like instances where they were stopped at a traffic light or quickly getting gas. I would say any instance where they have haven't moved more than .05 miles in more than 5 minutes would need to be considered an actual stop. 

    • rsimpson318's avatar
      rsimpson318
      Frequent Visitor

      Good afternoon tamerj1 .

       

      When I try to create the column for Adjusted Location, it gives an error that I've ran out of memory. Did you run into this when you were working on it?

      • tamerj1's avatar
        tamerj1
        Community Champion

        Morning rsimpson318 

        on sample I had no error. But this a heavy calculation and this is expected for big data. Do you have table for each vehicle or all in one table?