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
Anonymous
Not applicable

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]
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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])

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@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
Not applicable

@amitchandak 

 

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

😉😊

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

amitchandak
Super User
Super User

@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
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 

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.