Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hi,
I am having a brain block, trying to get this to work. I am trying to get the difference between each set of 'vehicle plate no', current mileage (based on rank).
Entries of the same 'vehicle plate no' will increase each month. Therefore the "Gen Difference" DAX needs to be dynamic.
This is an example of what I am trying to achieve.
DAX(Measure)
Rank's DAX is working perfectly fine but I couldn't get "VAR _RANK2GenHours" to automatically deduct 1 on each row.
I have tried "&& 'mMjIms8'[Rank] = 'mMjIms8'[Rank]-1, but this results in the entire column being blank.
What am I missing over here? 🙏
(Your help is much appreciated over here 👍)
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
OFFSET function (DAX) - DAX | Microsoft Learn
expected result measure: =
VAR _currentmileage =
SUM ( mMjIms8[current_mileage] )
VAR _previous =
CALCULATE (
SUM ( mMjIms8[current_mileage] ),
OFFSET (
-1,
SUMMARIZE (
ALL ( mMjIms8 ),
mMjIms8[vehicle_plate_no],
mMjIms8[date],
mMjIms8[current_mileage]
),
ORDERBY ( mMjIms8[date], ASC ),
,
PARTITIONBY ( mMjIms8[vehicle_plate_no] )
)
)
RETURN
IF (
NOT ISBLANK ( _previous ) && HASONEVALUE ( mMjIms8[vehicle_plate_no] ),
_currentmileage - _previous
)
Hi,
Please check the below picture and the attached pbix file.
OFFSET function (DAX) - DAX | Microsoft Learn
expected result measure: =
VAR _currentmileage =
SUM ( mMjIms8[current_mileage] )
VAR _previous =
CALCULATE (
SUM ( mMjIms8[current_mileage] ),
OFFSET (
-1,
SUMMARIZE (
ALL ( mMjIms8 ),
mMjIms8[vehicle_plate_no],
mMjIms8[date],
mMjIms8[current_mileage]
),
ORDERBY ( mMjIms8[date], ASC ),
,
PARTITIONBY ( mMjIms8[vehicle_plate_no] )
)
)
RETURN
IF (
NOT ISBLANK ( _previous ) && HASONEVALUE ( mMjIms8[vehicle_plate_no] ),
_currentmileage - _previous
)
Thanks Kim,
I got it to work with your help 🙏
Thanks Kim,
I got this to work with your solution. 🤝
Try
Gen Difference =
VAR FirstEntry =
INDEX (
1,
ALLSELECTED ( mMjIms8 ),
ORDERBY ( mMjIms8[Created At], DESC ),
PARTITIONBY ( mMjIms8[Vehicle Plate No] ),
MATCHBY ( mMjIms8[Vehicle Plate No] )
)
VAR SecondEntry =
INDEX (
2,
ALLSELECTED ( mMjIms8 ),
ORDERBY ( mMjIms8[Created At], DESC ),
PARTITIONBY ( mMjIms8[Vehicle Plate No] ),
MATCHBY ( mMjIms8[Vehicle Plate No] )
)
VAR FirstMileage =
SELECTCOLUMNS ( FirstEntry, mMjIms8[Current Mileage] )
VAR SecondMileage =
SELECTCOLUMNS ( FirstEntry, mMjIms8[Current Mileage] )
VAR Result = FirstMileage - SecondMileage
RETURN
Result
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 4 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 10 | |
| 8 | |
| 7 | |
| 6 |