Forum Discussion

Jimcint's avatar
Jimcint
New Member
2 years ago
Solved

Calculating difference between rows based on multiple columns

I have a large table that contains mass measurements from multiple tires at multiple mileages, as shown below:   I would like to create two new columns (MassLossKG and MileDiff) that contain ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi,

    PijushRoy , thanks for the concern about the question, and i want to offer some more infotmation for user to refer to.

    hello Jimcint , based on your description, you can refer to the following caucluated columns.

     

    MassLossKG =
    VAR a =
        CALCULATE (
            SUM ( 'Table'[TyreWheelMassKG] ),
            ALLEXCEPT ( 'Table', 'Table'[TyreSpec], 'Table'[TyreNum] ),
            'Table'[StopId]
                = EARLIER ( 'Table'[StopId] ) - 1
        )
    RETURN
        IF ( [Miles] <> 0, ABS ( [TyreWheelMassKG] - a ) )
    
    MileDiff =
    VAR a =
        CALCULATE (
            SUM ( 'Table'[Miles] ),
            ALLEXCEPT ( 'Table', 'Table'[TyreSpec], 'Table'[TyreNum] ),
            'Table'[StopId]
                = EARLIER ( 'Table'[StopId] ) - 1
        )
    RETURN
        IF ( [Miles] <> 0, ABS ( [Miles] - a ) )
    

     

    Output

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.