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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
deaconb
Frequent Visitor

Get lastest score and difference from previous

We have training data that looks like below:

TrainingIDNameResponseIDScoreLatest ScoreDifference from Previous Score
123A712541712-
123A712542322+1
123A712546132+1
123A712546522-1
234B712595513-
234B71259622

3

+1
234B712597833+1
234B7125985330
345A712599714-
345A713418324+1
345A713419134+1
345A713419644+1
345B713420413-
345B713425423+1
345B713426733+1

 

 

 

A "Name" can complete a given "TrainingID" however many times they want. Each time they compelete a TrainingID, they get a "Score". The training event is stored as a transaction in the database by "RecordID"; record IDs increment up 1 for each training event, so it can be used to order things chronologically 1-N, where item 1 was completed before item 2, etc. 

 

The first event of a given TrainingID for a Name, I don't need to return a value. All other events, I need to return the following: Latest Score (red) column and Difference from Previous Score (blue) column. I don't necessarily need the "+" in front of the positive increments, but I definitely need a negative value where they got a higher score the previous event than the lastest event. 

 

I've got the Latest Score (red) column working by using a Group By function. Where I'm stuck is getting the Difference from Previous Score (blue) column.

 

I've tried creating a measure with the following, but it's not returning the values based on the Training ID and Name, just the Training ID.

 

SELECTCOLUMNS(
    INDEX(
        -1,
ALLSELECTED(Query1[ResponseID], Query1[TrainingID], Query1[Score], Query1[Name]),
ORDERBY(Query1[ResponseID]),
PARTITIONBY(Query1[TrainingID], Query1[Name])
    ),
[Score])
 
 
Any help or guidance with the final column I need is greatly appreciated!! 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Very much the same formula, just use OFFSET instead of INDEX.

 

lbendlin_0-1714179335049.png

Latest Score = MAXX(INDEX(-1,ALL(Query1),PARTITIONBY([TrainingID],[Name]),MATCHBY([ResponseID])),[Score])

Difference = 
var a = MAXX(OFFSET(-1,ALL(Query1),PARTITIONBY([TrainingID],[Name]),MATCHBY([ResponseID])),[Score])
return if(not ISBLANK(a),[Score]-a)

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Very much the same formula, just use OFFSET instead of INDEX.

 

lbendlin_0-1714179335049.png

Latest Score = MAXX(INDEX(-1,ALL(Query1),PARTITIONBY([TrainingID],[Name]),MATCHBY([ResponseID])),[Score])

Difference = 
var a = MAXX(OFFSET(-1,ALL(Query1),PARTITIONBY([TrainingID],[Name]),MATCHBY([ResponseID])),[Score])
return if(not ISBLANK(a),[Score]-a)

 

Yes - that was it! Thank you SO much! I don't know why I didn't think to use OFFSET!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.