Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Simplifying a code using the "earlier" function

Hello,


I would like to filter the departure and arrival times of the cranes. I have a database with the times of the different cranes mixed together and with this code it calculates the intermediate time i.e. arrival time of the 1st crane - next departure time for the 1st crane.

The code sorts the filtered times by bridges but if I have a lot of lines this code does not work anymore because of the "earlier" function which is very greedy for the pc, how to simplify this code please?

 

CALCULATE(MIN('Bridge Hall 3 M'[DateHour_Origin]),FILTER('bridge Hall 3 M','bridge Hall 3 M'[Number_bridge]=EARLIER('bridge Hall 3 M'[Number_Pont])&&'bridge Hall 3 M'[DateHour_Origin]>EARLIER('bridge Hall 3 M'[DateHour_Origin])))-'bridge Hall 3 M'[Datehour_Arrival]
  • Anonymous , Sorry, Try like

     

    CALCULATE(MIN('Bridge Hall 3 M'[DateHour_Origin]),FILTER('bridge Hall 3 M','bridge Hall 3 M'[Number_bridge]=EARLIER('bridge Hall 3 M'[Number_Pont])
    &&'bridge Hall 3 M'[Date Rank] = EARLIER('bridge Hall 3 M'[Date Rank]) +1 ))-'bridge Hall 3 M'[Datehour_Arrival])

6 Replies

  • Anonymous , Create two columns

     

    Date Rank = rankx(Filter('bridge Hall 3 M' , [Number_bridge] = EARLIER('bridge Hall 3 M'[Number_Pont]) ), 'bridge Hall 3 M'[DateHour_Origin],,asc, dense)

     

    Col2 =

    CALCULATE(MIN('Bridge Hall 3 M'[DateHour_Origin]),FILTER('bridge Hall 3 M','bridge Hall 3 M'[Number_bridge]=EARLIER('bridge Hall 3 M'[Number_Pont])
    &&'bridge Hall 3 M'[Date Rank] = EARLIER('bridge Hall 3 M'[Date Rank] +1 )))-'bridge Hall 3 M'[Datehour_Arrival])

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi amitchandak,

       

      I get an error message "the first argument of earlier is not a valid column reference in the previous row context." for EARLIER('bridge Hall 3 M'[Date Rank] +1 

  • Anonymous's avatar
    Anonymous
    Not applicable

    I just passed but I don't get the right values...

    An example of the application I need:

    Deck 2 datetime departure: 20/07/22 01:06:23 dtatetime arrival: 20/07/22 01:07:23
    Deck 3 datetime departure: 20/07/22 03:00:26 datetime arrival: 20/07/22 03:07:26
    Deck 1 start time: 20/07/22 02:00:00 finish time: 20/07/22 02:04:05
    Deck 2 datetime departure : 20/07/22 03:08:00 dtatetime arrival : 20/07/22 03:09:55

    The code must take into account the bridge number, the departure time after 03:08:00 minus the arrival time before 01:07:23 = 2:00:37

  • Anonymous , Sorry, Try like

     

    CALCULATE(MIN('Bridge Hall 3 M'[DateHour_Origin]),FILTER('bridge Hall 3 M','bridge Hall 3 M'[Number_bridge]=EARLIER('bridge Hall 3 M'[Number_Pont])
    &&'bridge Hall 3 M'[Date Rank] = EARLIER('bridge Hall 3 M'[Date Rank]) +1 ))-'bridge Hall 3 M'[Datehour_Arrival])

    • Anonymous's avatar
      Anonymous
      Not applicable

      It doesn't give me the desired values, isn't there a way to have a code similar to my original code by removing "earlier"?

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak 

       

      I fiddled around a bit and ended up with the values I wanted, great, thanks a lot!

      😉😊