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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
bob57
Helper IV
Helper IV

Calculate difference of value in current row from value in previous row.

Hello. This seems simple enough but has offered me a bit of a challenge. I am seeking a DAX measure to solve this problem. I am also curious as to how a calculated column could do the same.

Eaxample data table:

DateCumulative Sold
1/1/20203
1/2/20205
1/3/202010
1/4/202014
1/5/202015
1/6/202020

 

I need to create a table visualization that displays the two columns from the data table (easy enough) and develop a DAX measure for the third column as shown below.

DateCumulative SoldDaily Num Sold
1/1/202033
1/2/202052
1/3/2020105
1/4/2020144
1/5/2020151
1/6/2020205

 

Thank you for your time and effort.

Bob

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

 

In your case:

Daily Num Sold Measure =
  VAR __Current = MAX('Table'[Cumulative Sold])
  VAR __Date = MAX('Table'[Date])
  VAR __PreviousDate = MAXX(FILTER('Table',[Date] < __Date),[Date])
  VAR __Previous = MAXX(FILTER('Table',[Date] = __PreviousDate),[Cumulative Sold])
RETURN
  __Current - __Previous


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

 

In your case:

Daily Num Sold Measure =
  VAR __Current = MAX('Table'[Cumulative Sold])
  VAR __Date = MAX('Table'[Date])
  VAR __PreviousDate = MAXX(FILTER('Table',[Date] < __Date),[Date])
  VAR __Previous = MAXX(FILTER('Table',[Date] = __PreviousDate),[Cumulative Sold])
RETURN
  __Current - __Previous


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
bob57
Helper IV
Helper IV

My apologies for the very poor colimn alignment.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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