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
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
Super User
Super User

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

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

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

@ 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!:
The Definitive Guide to Power Query (M)

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

My apologies for the very poor colimn alignment.

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