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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Dominok123
Frequent Visitor

Calculating Percentage Difference between Current and Previous Row only while the ID is the same

Hey guys,

I am struggling with trying and getting the third column '% Difference' (in the table below) working in Power BI. 

 

Basically I need to work out the percent difference of the current row of 'Value' when compared to the previous row in the 'Value' column. Furthermore, I can't have two different ID's being compared, hence why there is a 0 when the ID changes.

 

Any help would be much appreciated.

 

Table1:

IDValue% Difference
1500
1524
150-4
15510
2360
24010.5
3600
36620
362-6.2

 

2 ACCEPTED SOLUTIONS
PattemManohar
Community Champion
Community Champion

@Dominok123  Add a new column i.e. Index Field in "Power Query Editor" 

 

Then add a new column in DAX as below

 

% Difference = 
VAR _CurrVal = Test228RowDiff[Value]
VAR _PrevID = LOOKUPVALUE(Test228RowDiff[ID],Test228RowDiff[Index],Test228RowDiff[Index]-1)
VAR _PrevVal = LOOKUPVALUE(Test228RowDiff[Value],Test228RowDiff[Index],Test228RowDiff[Index]-1,Test228RowDiff[ID],Test228RowDiff[ID])
RETURN IF(Test228RowDiff[ID] = _PrevID,FORMAT((_CurrVal-_PrevVal)/_CurrVal,"Percent"),FORMAT(0,"Percent"))

image.png





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

Proud to be a PBI Community Champion




View solution in original post

Hi, I was just playing about with the problem when the solution was posted.  It's a good solution but i need to point out that the percentage calculation is wrong and there's a rogue non-existent table in the formula.

 

I also added the index column - because DAX engine has to know how to find the previous row.

For comparison, another DAX formula to get the previous value is

previous value = CALCULATE(FIRSTNONBLANK(Table2[Value], 1), 
FILTER(Table2, Table2[ID] = EARLIER(Table2[ID]) && Table2[Index] = EARLIER(Table2[Index]) - 1))

and the percentage calculation has to have the previous value as the denominator.

View solution in original post

4 REPLIES 4
PattemManohar
Community Champion
Community Champion

@Dominok123  Add a new column i.e. Index Field in "Power Query Editor" 

 

Then add a new column in DAX as below

 

% Difference = 
VAR _CurrVal = Test228RowDiff[Value]
VAR _PrevID = LOOKUPVALUE(Test228RowDiff[ID],Test228RowDiff[Index],Test228RowDiff[Index]-1)
VAR _PrevVal = LOOKUPVALUE(Test228RowDiff[Value],Test228RowDiff[Index],Test228RowDiff[Index]-1,Test228RowDiff[ID],Test228RowDiff[ID])
RETURN IF(Test228RowDiff[ID] = _PrevID,FORMAT((_CurrVal-_PrevVal)/_CurrVal,"Percent"),FORMAT(0,"Percent"))

image.png





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

Proud to be a PBI Community Champion




Legend

Hi, I was just playing about with the problem when the solution was posted.  It's a good solution but i need to point out that the percentage calculation is wrong and there's a rogue non-existent table in the formula.

 

I also added the index column - because DAX engine has to know how to find the previous row.

For comparison, another DAX formula to get the previous value is

previous value = CALCULATE(FIRSTNONBLANK(Table2[Value], 1), 
FILTER(Table2, Table2[ID] = EARLIER(Table2[ID]) && Table2[Index] = EARLIER(Table2[Index]) - 1))

and the percentage calculation has to have the previous value as the denominator.

Thanks@HotChilli  yes the index is pointing to wrong table, because of Lazy Intellisense option. Updated the table name now. 





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

Proud to be a PBI Community Champion




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.