Forum Discussion
tha_fanatic
1 year agoNew Member
Indexing Not working Properly - Dax Measure
Hi, I'm working on vehicle Mileage Data but my measure is returning an unexpected result in the 1st cell of the table as shown below. The Calculation is Mileage at Teco MINUS Prev. Mileage = Mileag...
- 1 year ago
Try this...
Previous Mileage = VAR __currentTECO = SELECTEDVALUE('Vehicle Mileage'[Mileage at TECO]) VAR __currentEquipment = SELECTEDVALUE('Vehicle Mileage'[Equipment]) VAR __currentMntPlan = SELECTEDVALUE('Vehicle Mileage'[MntPlan]) VAR __result = CALCULATE( MAX('Vehicle Mileage'[Mileage at TECO]) ,FILTER( ALL('Vehicle Mileage') ,'Vehicle Mileage'[Equipment] = __currentEquipment && 'Vehicle Mileage'[MntPlan] = __currentMntPlan && 'Vehicle Mileage'[Mileage at TECO] < __currentTECO ) ) RETURN __result - 1 year ago
Hi,
I tried to create a sample pbix file like below, and tried to use offset dax function in the measure.
Please check the below picture and the attached pbix file.
Prev. mileage: = SUMX ( OFFSET ( -1, ALL ( vehicle[equipment], vehicle[mintplan], vehicle[uniqueID], vehicle[mileage] ), ORDERBY ( vehicle[mintplan], ASC ), , PARTITIONBY ( vehicle[mintplan], vehicle[equipment] ) ), vehicle[mileage] ) - 1 year ago
Hi Jihwan,
This worked a treat. Many thanks for your help.
KNP
Super User
1 year agoTry this...
Previous Mileage =
VAR __currentTECO = SELECTEDVALUE('Vehicle Mileage'[Mileage at TECO])
VAR __currentEquipment = SELECTEDVALUE('Vehicle Mileage'[Equipment])
VAR __currentMntPlan = SELECTEDVALUE('Vehicle Mileage'[MntPlan])
VAR __result =
CALCULATE(
MAX('Vehicle Mileage'[Mileage at TECO])
,FILTER(
ALL('Vehicle Mileage')
,'Vehicle Mileage'[Equipment] = __currentEquipment
&& 'Vehicle Mileage'[MntPlan] = __currentMntPlan
&& 'Vehicle Mileage'[Mileage at TECO] < __currentTECO
)
)
RETURN __result
- tha_fanatic1 year agoNew Member
Hi KNP,
This solution worked for me. I appreciate your help.
Kind Regards,