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
JunMenoza
New Member

Help Dax

image.pngHi , How would I add previous transaction in the Prev_trans columm

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@JunMenoza You need a variation on MTBF. 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....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
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

Whitewater100
Solution Sage
Solution Sage

Hi:

If you can put the date in the table e.g. 4-10-2021  and add an index column using Power Query (1 -8) then this calculated column will work for you.

Previous Value 2 =
CALCULATE(
LASTNONBLANKVALUE(Data[Date], SUM(Data[Mileage])),
ALLEXCEPT(Data, Data[Sales Rep]),
Data[Index]<EARLIER(Data[Index]) &&
Data[Day]
)
Here is a picture of the results:(I named your table Data)
Whitewater100_0-1649167127203.png

To put an index column in, go to transform data, "add index column (from 1). Here is an example file. I hope this solves your question!

https://drive.google.com/file/d/1NmKBreErOFNw8EqCo3yHMvItL_p7QZkE/view?usp=sharing 

View solution in original post

2 REPLIES 2
Whitewater100
Solution Sage
Solution Sage

Hi:

If you can put the date in the table e.g. 4-10-2021  and add an index column using Power Query (1 -8) then this calculated column will work for you.

Previous Value 2 =
CALCULATE(
LASTNONBLANKVALUE(Data[Date], SUM(Data[Mileage])),
ALLEXCEPT(Data, Data[Sales Rep]),
Data[Index]<EARLIER(Data[Index]) &&
Data[Day]
)
Here is a picture of the results:(I named your table Data)
Whitewater100_0-1649167127203.png

To put an index column in, go to transform data, "add index column (from 1). Here is an example file. I hope this solves your question!

https://drive.google.com/file/d/1NmKBreErOFNw8EqCo3yHMvItL_p7QZkE/view?usp=sharing 

Greg_Deckler
Community Champion
Community Champion

@JunMenoza You need a variation on MTBF. 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....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
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...

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.