Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
jeffw14
Helper I
Helper I

Getting Date from Next Row

Need DAX code to get the date from the row of that vehicle ID's next pickup. Have Vehicle ID data that contains a Pickup Date and a Drop Date with the State it drops in. I need to know how long each vehicle sat in each state (each row) by getting the next pickup date for that vehicle and taking the date difference from the Drop Date and the Next Pick Up Date. I did add an Index column in Power Query and did this as a Calculated Column but the dataset is very large and takes way too long to refresh. Here is an example of the data:

VehicleIDPickupDateDropDateDropStateNextPickupDateDaysSitting
344410/1/202410/3/2024MO10/6/2024                    3
410010/1/202410/2/2024IL10/5/2024                    3
410010/5/202410/6/2024KY10/7/2024                    1
344410/6/202410/7/2024OH10/9/2024                    2
410010/7/202410/8/2024TN10/9/2024                    1

 

Thanks

5 REPLIES 5
Anonymous
Not applicable

Hi, @jeffw14 

 

You can try the following methods.

Measure = 
Var _Nextpickup=CALCULATE(MIN('Table'[PickupDate]),FILTER(ALLEXCEPT('Table','Table'[VehicleID]),[PickupDate]>MAX('Table'[PickupDate])))
Var _diff=ABS(DATEDIFF(MAX('Table'[DropDate]),_Nextpickup,DAY))
RETURN
IF(_Nextpickup<>BLANK(),_diff)

vzhangtinmsft_0-1728525299318.png

Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you, as an added wrinkle to this that I forgot, if the vehicle has a drop date before today's date and no pickup after that, is there a way to always default the Next Pickup Date calculation to today's date? Then the Next Pickup Date would continue to automatically update and thus update the amount of time the driver is sitting, until the driver receives their next pickup and another entry is added to the database.

Anonymous
Not applicable

Hi, @jeffw14 

 

Please provide some of the sample data and the output you expect.

 

Best Regards

vicky_
Super User
Super User

Here's the code for my Next Pickup Date measure:

Next Pick Up = CALCULATE(MIN('Table'[PickupDate]), OFFSET(1, ALL('Table'), ORDERBY('Table'[PickupDate], ASC), PARTITIONBY('Table'[VehicleID]), MATCHBY('Table'[VehicleID], 'Table'[PickupDate])))

Note - if you've got an index column, you can use that in the MATCHBY instead of VehicleID and PickupDate.

You can then do a simple subtraction to get the days sitting.

Thank you, as an added wrinkle to this that I forgot, if the vehicle has a drop date before today's date and no pickup after that, is there a way to always default the Next Pickup Date calculation to today's date? Then the Next Pickup Date would continue to automatically update and thus update the amount of time the driver is sitting, until the driver receives their next pickup and another entry is added to the database.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.