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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
frankly
Frequent Visitor

Row differences using DAX (PowerBI)

¿What would be the simplest DAX formula in PowerBI to calculate row differences?

 

I tried using EARLIER() but it cannot handle the operation at the limit (missing data):

EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

 

rowvaluediff(value)?
15 
21-4
365
471
53-4
630
71-2
810
987

 

 

4 REPLIES 4
rubayatyasmin
Community Champion
Community Champion

Hi, @BjoernSchaefer 

 

try this

 

Difference =
CALCULATE(
SUM('Data'[value]),
FILTER(
ALL('Data'),
'Data'[row] = EARLIER('Data'[row]) - 1
)
) - 'Data'[value]

 

the code will only work if your row column has unique value. If not then create an index column starting from 0. 

 

If you have missing values in your value column then try this: make sure you have an index column starting from0

 

Difference =
LOOKUPVALUE (
Data[value],
Data[Index],
Data[Index] - 1,
BLANK ()
) - Data[value]

 

 

 

this thread might help:

 

Solved: I need output like this by using measure ( calcula... - Microsoft Fabric Community

 

rubayatyasmin_0-1689517080227.png

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


@frankly Or you can use IF statememnt:

 

Difference =
IF(
Tabelle[row] = 1,
BLANK(),
(LOOKUPVALUE(Tabelle[value], Tabelle[row], Tabelle[row] - 1) - Tabelle[value]) * -1
)

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


ERD
Community Champion
Community Champion

Hi @frankly ,

You can try this measure:

 

diff =
VAR _current_row = SELECTEDVALUE ( Table_[row] )
VAR _current_value = SELECTEDVALUE ( Table_[value] )
VAR _prev_row = MAXX ( FILTER ( ALL ( Table_[row] ), Table_[row] < _current_row ), Table_[row] )
VAR _prev_value = MAXX ( FILTER ( ALL ( Table_ ), Table_[row] = _prev_row ), Table_[value] )
RETURN
    IF ( NOT ISBLANK ( _prev_value ), _current_value - _prev_value )

 

ERD_0-1690877361648.png+

For the calculated coumn:

Column =
VAR _current_row = Table_[row]
VAR _current_value = Table_[value]
VAR _prev_row = MAXX ( FILTER ( VALUES ( Table_[row] ), Table_[row] < _current_row ), Table_[row] )
VAR _prev_value = MAXX ( FILTER ( Table_, Table_[row] = _prev_row ), Table_[value] )
RETURN
    IF ( NOT ISBLANK ( _prev_value ), _current_value - _prev_value )

 



If this post helps, then please considerAccept it as the solution to help the other members find it more quickly.
Appreciate your Kudos
Stand with Ukraine! 

BjoernSchaefer
Helper II
Helper II

Hey frankly,

 

i was able to do it with SWITCH and LOOKUPVALUE.
Maybe there's a more elegant way.

formula = SWITCH(TRUE(),Tabelle[row]=1,BLANK(),(LOOKUPVALUE(Tabelle[value],Tabelle[row],Tabelle[row]-1)-Tabelle[value])*-1)

Kind Regards

 

Björn

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.