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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
alevandenes
Helper IV
Helper IV

difference between consecutive dates rows

Hi Community,

i need some help to write a formula.

For every driver, as you can see in overview below, i have some transaction dates and the mileage that they recorded in the system.

I need to calculate the difference between the two consecutive dates. in particular, i need a formula that calculates automatically that driver X has driven 1374 Kms (168128 minus 155754) between 16-oct-2019 and 30-oct-2019.

 

alevandenes_0-1647335507809.png

could you help me with this?

 

Kind regards

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @alevandenes,

Here are the steps you can follow:

1. Create measure.

difference between the two consecutive dates =
var _closestdate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[driver]=MAX('Table'[driver])&&'Table'[Date]<MAX('Table'[Date])))
return
MAX('Table'[Milage]) -  CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[driver]=MAX('Table'[driver])&&'Table'[Date]=_closestdate))
driverX_date =
var _date1016=CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[Date]=DATE(2019,10,16)&&'Table'[driver]="driver X"))
var _date1030=CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[Date]=DATE(2019,10,30)&&'Table'[driver]="driver X"))
return
_date1030 - _date1016

2. Result:

vyangliumsft_0-1647587471673.png

Best Regards,

Liu Yang

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @alevandenes,

Here are the steps you can follow:

1. Create measure.

difference between the two consecutive dates =
var _closestdate=CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[driver]=MAX('Table'[driver])&&'Table'[Date]<MAX('Table'[Date])))
return
MAX('Table'[Milage]) -  CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[driver]=MAX('Table'[driver])&&'Table'[Date]=_closestdate))
driverX_date =
var _date1016=CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[Date]=DATE(2019,10,16)&&'Table'[driver]="driver X"))
var _date1030=CALCULATE(SUM('Table'[Milage]),FILTER(ALL('Table'),'Table'[Date]=DATE(2019,10,30)&&'Table'[driver]="driver X"))
return
_date1030 - _date1016

2. Result:

vyangliumsft_0-1647587471673.png

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@alevandenes , a new column or measure

 

new column =
var _max = maxx(filter(Table, [Diver] = earlier([Driver]) && [Date] < earlier([date])),[Date])
return
[KMS] - maxx(filter(Table, [Diver] = earlier([Driver]) && [Date] =_max),[KMS])


new measure =
var _max = maxx(filter(allselected(Table), [Diver] = max([Driver]) && [Date] < max([date])),[Date])
return
sum([KMS]) - maxx(filter(allselected(Table), [Diver] = max([Driver]) && [Date] =_max),[KMS])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.