Forum Discussion

tha_fanatic's avatar
tha_fanatic
New Member
1 year ago
Solved

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...
  • KNP's avatar
    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

     

     

  • Jihwan_Kim's avatar
    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]
    )
  • tha_fanatic's avatar
    tha_fanatic
    1 year ago

    Hi Jihwan,

     

    This worked a treat. Many thanks for your help.