Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jimcint
New Member

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:

Jimcint_1-1716391195935.png

 

I would like to create two new columns (MassLossKG and MileDiff) that contain the difference in mass and miles from consecutive measurements of the same tire (same TyreSpec and TyreNum), So, I'm looking for somethine like this:

MilesTyreSpecTyreNumTyreWheelMassKGMassLossKGMileDiff
8000C321.25.04800
0C422.38nullnull
800C422.36.02800
1600C422.34.02800
2400C422.28.06800
3200C422.24.04800
4000C422.18.06800
4800C422.14.04800
5600C422.11.03800
6400C422.1.01800
7200C422.03.07800
8000C422.01.02800
0D123.12nullnull

 

Is it possible to do something like this in DAX? How?

If it's not possible to use null or blank values for the 0 mile cases, then 0 is okay. 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

vxinruzhumsft_0-1716792812480.png

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.

 

View solution in original post

4 REPLIES 4
PijushRoy
Super User
Super User

Hi @Jimcint 

Your requirements and examples are not clear to me. Can you add more details?
In MassLossKG column 1st value 0.04, what is the calculation?




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





For the fourth row of the table, tire C 4 is at 1600 miles. the mass is 22.34 kg. The previous measurement is 800 miles with a mass of 22.36 kg. so mass loss is 22.36 - 22.34 = 0.02 measurement distance is 1600 - 800 = 800. 

for the first (0 mile) measurement, there is nothing to subtract from, so the results would be null, 0, or blank. 

Anonymous
Not applicable

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

vxinruzhumsft_0-1716792812480.png

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.

 

Thank you. This is very helpful. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.