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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
liamcol
Helper I
Helper I

Creating a measure in Dax to calculate difference between two rows (similar to excel)

liamcol_0-1613347955854.png

I would like to create a new column which would measure the difference between the two rows to find the "scan length"


What would be the DAX formula for this?  

 

Thanks!

 

4 REPLIES 4
wdx223_Daniel
Super User
Super User

new column=maxx(filter(table,table[Local Time]>earlier(table[Local Time])),table[Local Time])-table[Local Time]

Nathaniel_C
Super User
Super User

Hi @liamcol 
Try this:

 

Diff = 
var _curMeasure = MAX(myTable[Measure]) //This row's measure
var _curTime = MAX(myTable[Time])       //This row's time


var _calc = CALCULATE(MAX(myTable[Measure]),FILTER(ALL(myTable),myTable[Time]<_curTime))  //Get the measure of the previous row


return IF(_curMeasure-_calc=_curMeasure,0,_curMeasure-_calc)  //if there is no previous measure, then 0 else the diff

 

image.png

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




I am unsure what to put for this rows measure? 

 

Thanks

 

Hi @liamcol ,
As you did not supply us with a pbix, I created a quick table called myTable with the columns named Time and Measure. 

mytable.PNG


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors