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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
ScottGunsaullus
Frequent Visitor

Measure compares client's value to most recent previous value (improved, not improved, same)

Sample data:

PHQ9_sample.png

For each row and client [PATID], I need to calculate 3 things: 

  1. Was there a previous [total_score] and if so,
  2. What was the previous [total_score]?
  3. What was the difference between the [total_score] and the previous [total_score]?

Zero is a valid score.  Lower scores are better.  So, a negative difference would indicate improvement.

PHQ9_sample2.png

 

 

 

2 ACCEPTED SOLUTIONS
Selva-Salimi
Solution Sage
Solution Sage

Hi @ScottGunsaullus 

 

you can write these 3 columns :

 

Prev_assessment = if (calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date]))) <> Blank() , "Yes" , "No")
 
Prev_total_score =
var prev_date = calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date])))
return
CALCULATE(max('Your_table'[total_score]) , filter('Your_table','Your_table'[assessment_date] = prev_date
&& Your_table[PATID]=EARLIER(Your_table[PATID])
))
 
difference = 'Your_table'[total_score] - 'Your_table'[Prev_total_score]
 
If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly.
 

 

View solution in original post

@Selva-Salimi 

I had to make a minor change to the second column. CALCULATE needs to consider both PATID and assessment_date.

I could not have solved this without your help.  Thanks again,

 

Prev_total_score =
var prev_date = calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date])))
return
CALCULATE(max('Your_table'[total_score]) , ALLEXCEPT ( 'Your_table', 'Your_table'[PATID]), 'Your_table'[assessment_date] = prev_date)

View solution in original post

3 REPLIES 3
Selva-Salimi
Solution Sage
Solution Sage

Hi @ScottGunsaullus 

 

you can write these 3 columns :

 

Prev_assessment = if (calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date]))) <> Blank() , "Yes" , "No")
 
Prev_total_score =
var prev_date = calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date])))
return
CALCULATE(max('Your_table'[total_score]) , filter('Your_table','Your_table'[assessment_date] = prev_date
&& Your_table[PATID]=EARLIER(Your_table[PATID])
))
 
difference = 'Your_table'[total_score] - 'Your_table'[Prev_total_score]
 
If this post helps, then I would appreciate a thumbs up 👍 and mark it as the solution to help the other members find it more quickly.
 

 

@Selva-Salimi 

I had to make a minor change to the second column. CALCULATE needs to consider both PATID and assessment_date.

I could not have solved this without your help.  Thanks again,

 

Prev_total_score =
var prev_date = calculate(max('Your_table'[assessment_date]) , FILTER('Your_table' , 'Your_table'[PATID]=EARLIER('Your_table'[PATID]) && 'Your_table'[assessment_date] < EARLIER('Your_table'[assessment_date])))
return
CALCULATE(max('Your_table'[total_score]) , ALLEXCEPT ( 'Your_table', 'Your_table'[PATID]), 'Your_table'[assessment_date] = prev_date)

@ScottGunsaullus 

 

thanks to pointing that out. you are right, one filter was missed. I have updated my previous response. I would appriciate to mark it as solution to help others find it quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.