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
fatimaarshd
Helper I
Helper I

How to get previous row value of a measure?

I have been stuck at this for quite some time now. I have a table in which I create measures. Length is a column here. survival proportion m1 is a measure which takes into account two other measures total patients m1 and finished patients m1. These are how measures are calculated. 

Total Patients m1 =
VAR CurrentLength = SELECTEDVALUE(SDP_Patients[Length])
RETURN
CALCULATE(
DISTINCTCOUNT(SDP_Patients[RequestNumber]),
SDP_Patients[Length] >= CurrentLength,
ALLSELECTED(SDP_Patients))

 

and

 

Finished Patients m1 =
VAR CurrentLength = MAX(KM[Length])
VAR Result =
CALCULATE(
DISTINCTCOUNT(SDP_Patients[RequestNumber]),
SDP_Patients[Length] = CurrentLength && NOT(ISBLANK(SDP_Patients[ServiceEndDate])),
ALLSELECTED(SDP_Patients)
)
RETURN
IF(ISBLANK(Result), 0, Result)

 

and

survival proportion m1 = DIVIDE(([Total Patients m1] - [Finished Patients m1]),[Total Patients m1],0)

 

finally,

test1 =
VAR CurrentLength = MAX('SDP_Patients'[Length])
VAR CurrentValue = [survival proportion m1]

VAR PreviousRow =
TOPN (
1,
FILTER (
ALLSELECTED(SDP_Patients),
SDP_Patients[LENGTH] < CurrentLength

),
[Length], DESC
)
VAR PreviousValue =
MAXX ( PreviousRow, [survival proportion m1] )

RETURN
IF(
CurrentLength = 0,
CurrentValue, // Return the current value as is for the first row
PreviousValue

)

 

I have broken down my entire problem to this. I have tried every solution but no use. It just doesnt return previous value. My guess is that since its a measure thats why. 

In the end I will be taking cummulative product. But I have to solve this issue before moving on to that because that doesnt work either.

 

fatimaarshd_0-1696357671029.png

Length is non unique in original table. this is a table visual

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@fatimaarshd So, in theory something like this *should* work:

PV m1 = 
  VAR __Table = 
    SUMMARIZE(
      ALLSELECTED('SDP_Patients'), 
      [Length], 
      "__TotalPatients", [Total Patients m1], 
      "__SurvivalProportion", [survival proportion m1]
    )
  VAR __Length = MAX('SDP_Patients'[Length])
  VAR __PrevLength = __Length - 1
  VAR __Result = MAXX( FILTER( __Table, [Length] = __PrevLength ), [__SurvivalProportion] )
RETURN
  __Result


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

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@fatimaarshd So, in theory something like this *should* work:

PV m1 = 
  VAR __Table = 
    SUMMARIZE(
      ALLSELECTED('SDP_Patients'), 
      [Length], 
      "__TotalPatients", [Total Patients m1], 
      "__SurvivalProportion", [survival proportion m1]
    )
  VAR __Length = MAX('SDP_Patients'[Length])
  VAR __PrevLength = __Length - 1
  VAR __Result = MAXX( FILTER( __Table, [Length] = __PrevLength ), [__SurvivalProportion] )
RETURN
  __Result


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

Thank you so much. It worked!!!!!!!!! Been stuck on this for a day. 

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.