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

Calculated Column to Retrieve previous date where value was different (Filtered by criteria)

Hi all,

I am attempting to find previous last_run date where the position value was different in a records table based on the ID and product being the same. So following the table below, when the position value column was last different and have that shown in a table as a calculated column.

 

idpositionproductlast_runDesired Column - Previous PositionDesired Column - Previous date
0012000000bkPfwAAEBottomProduct A01-Sep-24Middle01-Jun-24
0012000000bkPfwAAEMiddleProduct A15-Aug-24Top01-May-24
0012000000bkPfwAAEMiddleProduct A01-Aug-24Top01-May-24
0012000000bkPfwAAEMiddleProduct A15-Jul-24Top01-May-24
0012000000bkPfwAAEMiddleProduct A09-Jul-24Top01-May-24
0012000000bkPfwAAEMiddleProduct A15-Jun-24Top01-May-24
0012000000bkPfwAAEMiddleProduct A01-Jun-24Top01-May-24
0012000000bkPfwAAETopProduct A01-May-24Middle01-Feb-24
0012000000bkPfwAAETopProduct A01-Apr-24Middle01-Feb-24
0012000000bkPfwAAETopProduct A01-Mar-24Middle01-Feb-24
0012000000bkPfwAAEMiddleProduct A01-Feb-24Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct A01-Jan-24Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct A01-Dec-23Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct A01-Nov-23Middle01-Nov-23
0012000000bkPfwAAEBottomProduct B01-Sep-24Middle01-Jun-24
0012000000bkPfwAAEMiddleProduct B15-Aug-24Top01-May-24
0012000000bkPfwAAEMiddleProduct B01-Aug-24Top01-May-24
0012000000bkPfwAAEMiddleProduct B15-Jul-24Top01-May-24
0012000000bkPfwAAEMiddleProduct B09-Jul-24Top01-May-24
0012000000bkPfwAAEMiddleProduct B15-Jun-24Top01-May-24
0012000000bkPfwAAEMiddleProduct B01-Jun-24Top01-May-24
0012000000bkPfwAAETopProduct B01-May-24Middle01-Feb-24
0012000000bkPfwAAETopProduct B01-Apr-24Middle01-Feb-24
0012000000bkPfwAAETopProduct B01-Mar-24Middle01-Feb-24
0012000000bkPfwAAEMiddleProduct B01-Feb-24Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct B01-Jan-24Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct B01-Dec-23Middle01-Nov-23
0012000000bkPfwAAEMiddleProduct B01-Nov-23Middle01-Nov-23



I have attempted using MAX function in a calculated column but I dont think I am getting the variables right. 

Would be great to get your assistance 🙂

Thank you

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@CRanjan12 See my article on Mean Time Between Failure (MTBF) which uses EARLIER. In this case, you would just need to stop at PreviousDate variable (see below). And of course include your ID and Product name in your filter.

 

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 ) * 1.



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 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.

June 2025 community update carousel

Fabric Community Update - June 2025

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