The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello! I am having some trouble creating a calculated column to find the difference in mileage between consecutive rows based on the vehicle + driver calculated field.
I created two index fields to help identify the order in which to subtract the consecutive rows, but I want to include a grouping criteria to only find the difference if the VINName (calculated column) is the same. I'm trying to eliminate calculations for the very first row of data per VINName showed on the 1/6/2024 line item. I tried including an EARLIER experession with the VINName, but I don't think that column is compatible with the EARLIER expression. Below is a snip of the data in a pivot.
Here's what I currently have for DAX:
ODOMVAR = VAR Diff = 'Odometer Helper'[Fuel Odometer] -
CALCULATE(SUM('Odometer Helper'[Fuel Odometer]),
FILTER('Odometer Helper','Odometer Helper'[Index01]=EARLIER('Odometer Helper'[Index])
)
)
RETURN
IF(
Diff=VALUE('Odometer Helper'[Fuel Odometer]),
0,
Diff
)
Solved! Go to Solution.
Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:
Hi @Anonymous ,
You can try the following calculated columns:
ODOMVAR =
var _mindate=
MINX(FILTER(ALL('Odometer Helper'),'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])),[Date])
var _lastdate=
MAXX(
FILTER(ALL('Odometer Helper'),
'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])&&
'Odometer Helper'[Date]<EARLIER('Odometer Helper'[Date])),'Odometer Helper'[Date])
RETURN
IF(
'Odometer Helper'[Date]=_mindate,BLANK(),
'Odometer Helper'[Fuel Odometer]-
SUMX(
FILTER(ALL('Odometer Helper'),
'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])&&
'Odometer Helper'[Date]=_lastdate),[Fuel Odometer]))
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.
Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:
Hi @Anonymous ,
You can try the following calculated columns:
ODOMVAR =
var _mindate=
MINX(FILTER(ALL('Odometer Helper'),'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])),[Date])
var _lastdate=
MAXX(
FILTER(ALL('Odometer Helper'),
'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])&&
'Odometer Helper'[Date]<EARLIER('Odometer Helper'[Date])),'Odometer Helper'[Date])
RETURN
IF(
'Odometer Helper'[Date]=_mindate,BLANK(),
'Odometer Helper'[Fuel Odometer]-
SUMX(
FILTER(ALL('Odometer Helper'),
'Odometer Helper'[VINName]=EARLIER('Odometer Helper'[VINName])&&
'Odometer Helper'[Date]=_lastdate),[Fuel Odometer]))
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.
Ah, yes! The Filter and SUMX at the end worked perfectly for me. Thanks so much!
@Anonymous See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
( __Current - __Previous ) * 1.
This worked in the sense that the EARLIER function processed, but I am still having trouble grouping my data by the calculated column, VINName. If there's a way to incorporate that into my existing DAX function, I think that would solve my problem more directly.
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
20 | |
12 | |
9 | |
7 |