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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors