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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Zbig62
Regular Visitor

SUM OF DIFFERENCES - DAX FORMULA

Hello everyone and please help

 

MY PROBLEM

In the table "TABLE1" I have the values ​​"id" and "Value". The measure "Value n-1" calculates the value from the previous row of the table. The column "Differ" is a measure that calculates the difference between "Value" and "Value n-1". At the level of a single row in the table, everything is calculated correctly. However, I need to calculate the sum of differences from the column "Differ". The calculated value in the table "Table1" should be "10" but it is "37". The problem probably lies in the lack of a sum of values ​​for the column "Value n-1". What am I doing wrong? Please help

 

Zbig62_0-1726342547907.png

 

Value n-1 =

var a =

 CALCULATE(

    max(TABLE1[id]);

    FILTER(

        ALLSELECTED(TABLE1[id]);TABLE1[id] < SELECTEDVALUE(TABLE1[id])

    )

 )

 RETURN

  CALCULATE(

    SUMX(TABLE1;TABLE1[Value]);TABLE1[id] = a

 )

 

Differ =

var a = TABLE1[Value n-1]

RETURN

   sumx(TABLE1;TABLE1[Value] - a)

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Zbig62,

 

Try these measures:

 

Sum of Value = SUM ( Table1[Value] )
Value n-1 = 
CALCULATE (
    [Sum of Value],
    OFFSET ( -1, ALLSELECTED ( Table1[id] ), ORDERBY ( Table1[id], ASC ) )
)
Differ = [Sum of Value] - [Value n-1]

 

DataInsights_0-1726524025301.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@Zbig62,

 

Try these measures:

 

Sum of Value = SUM ( Table1[Value] )
Value n-1 = 
CALCULATE (
    [Sum of Value],
    OFFSET ( -1, ALLSELECTED ( Table1[id] ), ORDERBY ( Table1[id], ASC ) )
)
Differ = [Sum of Value] - [Value n-1]

 

DataInsights_0-1726524025301.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much for your support
everything works fine

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.