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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sukram1
Frequent Visitor

Difference from previous row based on measure

Hi,

I am trying to create the difference from the previous row based on a measure. I have the following initial situation:

Difference Measure.png

  • The first two columns are attributes from the dataset.
  • The first measure calculates the ratio of premium1 to premium 2.
  • The next two columns are also Measures, which calculates the difference to the previous rows. For this I use a column with an index (running number), which was inserted in the dataset as an additional column.
  • The last measure again determines the ratio between the two previous columns.
  • The orange colored column is what I want to determine.

I want to determine the difference to the previous column based on the measure. I have already tried to use RANKX to classify the measure accordingly (like an index) and to calculate the difference based on this classification. But this does not give any result.

Is it at all possible to calculate the difference to the value from the previous row based on a measure?

 

Many thanks in advance!

 

2 REPLIES 2
Anonymous
Not applicable

Hi  @sukram1 ,

 

Here are the steps you can follow:

1. Create measure.

Difference =
var _current=
SUMX(
    FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])),[Diff_P1/Diff_P2])
var _last=
SUMX(
    FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1),[Diff_P1/Diff_P2])
return
IF(
    _last=BLANK(),BLANK(),
_current - _last)

2. Result:

vyangliumsft_0-1691561500034.png

If I have misunderstand your meaning, please contact me and provide your desired output.

 

Best Regards,

Liu Yang

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

HI @Anonymous,

Thank you very much for your help and your solution. You got it right and it is exactly what I am looking for!

 

Unfortunately, the solution does not work with my data. I suspect that I have created the measure for the difference incorrectly. Here is my result:
Difference_2.png

This is how I created the Measures, which determines the difference between the two premiums:

Diff_P1 = 
VAR currIndex = 
    MAX(Test_Table[Index])
VAR vP1 =
    CALCULATE(
            SUM(Test_Table[Premium_1]);
            FILTER(ALLSELECTED(Test_Table); [Index] <= currIndex)
    )
RETURN
    vP1
Diff_P2 = 
VAR currIndex = 
    MAX(Test_Table[Index])
VAR vP2 =
    CALCULATE(
            SUM(Test_Table[Premium_2]);
            FILTER(ALLSELECTED(Test_Table); [Index] <= currIndex)
    )
RETURN
    vP2

 Somehow the solution for me ignores to consider the measure Diff_P1/Diff_P2. Therefore, the error can only be in my previous data steps.

Best regards,
Markus

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.

Top Solution Authors
Top Kudoed Authors