Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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.
could you help me with this?
Kind regards
Solved! Go to Solution.
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:
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
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:
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
@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])
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.