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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
v-zhangtin-msft
Community Support
Community Support

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.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.