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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.