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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.