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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
JustDavid
Helper IV
Helper IV

Comparison against Previous Record

Hello,

 

I'm new with DAXand my logic is still with Excel.

 

Using Calculated Column with DAX (not in Power Query), how do I check my current record against previous record?

 

DataDesired Result

A

1
A1
B2
B2
B2
C3
C3
D4
E5
F6
F6

 

The logic that I want here is that if I'm the 1st record, then assign value 1 otherwise check against previous record, and if previous record is the same as current record, take the above assign value otherwise add 1

4 REPLIES 4
JustDavid
Helper IV
Helper IV

Thanks for the reply @Greg_Deckler .

 

I have questions regarding your DAX formula.

 

Using my table above as example, 

  1. Would this VAR __Current = [Desired Result] return the current value? If it is, my question would then be, how does it know to assign a value 1 to the 1st record and then either stay or add a counter?
  2. VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date]). I'd assume your 'Date' here refers to my 'DATA' column? And if it is, then would MAXX works with string data type?

 

 

 

@JustDavid You are going to need to add an Index to your table to be able to let DAX know what "before" is.



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

Sorry...I don't quite understand.

 

Even if I were to add an index column (I'd assume starting from 0), in which formula do I use it in?

 

Is it in VAR __PreviousData = MAXX(FILTER('Table','Table'[DATA] < EARLIER('Table'[DATA])),[INDEX])?

 

Again. How do I assign value 1 to the 1st record of the column 'Desired Result'?

 

Just to be clear, This is the logic that I had with Excel.

  1. Put a value 1 in the 1st record in column 'Desired Result'.
  2. Add a counter: Add a counter to 'Desired Result' column from the previous record of [DESIRED RESULT] IF AND ONLY IF when the current record [DATA] is not the same as the previous record [DATA]  i.e. Use previous row value from the 'Desired Result' + 1 If current record [DATA] is NOT the same as previous record of the [DATA].
  3. Do not add counter: Take the value from 'Desired Result' column of the previous record of [DESIRED RESULT] IF AND ONLY IF when the current record [DATA] is the same as the previous record [DATA]  i.e. Use previous row value from the 'Desired Result' If current record [DATA] is the same as previous record of the [DATA].

 

Greg_Deckler
Community Champion
Community Champion

@JustDavid 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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.