Forum Discussion
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 = MileageDiff. Prev.Mileage & Mileage Diff first rows need to be blank.
Looks like the measure is picking up the Max Mileage at TECO and using it to fill up the first cell in Prev.Mileage to get the 'Mileage Diff'. The first cell in 'Prev.Mileage' and 'Mileage Diff' need to be blank. How do I prevent this from happening? Please help
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 __resultHi,
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] )Hi Jihwan,
This worked a treat. Many thanks for your help.
4 Replies
- KNP
Super User
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- tha_fanaticNew Member
Hi KNP,
This solution worked for me. I appreciate your help.
Kind Regards,
- Jihwan_Kim
Super User
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] )- tha_fanaticNew Member
Hi Jihwan,
This worked a treat. Many thanks for your help.