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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rishtin
Frequent Visitor

Difference between exam scores by multiple dates

Hello,

 

I have a table with StudentID, Score and TestDate columns. I am trying to identify the difference in scores between two dates. When there are only two TestDates for a student then I can manage that, however when there are more than 2 then there's a problem with my dax.

 

Here's what i am trying to achieve;

StudentID, Score, TestDate, DifferenceinScore
stud001, 90, 2019-01-15, blank

stud001, 95, 2019-01-20, 5

stud001, 96, 2019-02-15, 1

 

How could i do this in a calculated column?
thanks

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @rishtin 

Give this a try.

Score Change = 
VAR CurrStudent = 'Table'[StudentID]
VAR CurrDate = 'Table'[TestDate]
VAR PrevTestDate = 
CALCULATE( 
    MAX ( 'Table'[TestDate] ), 
    ALL ( 'Table' ), 
    'Table'[StudentID] = CurrStudent, 
    'Table'[TestDate] < CurrDate
)
RETURN
IF ( 
    NOT ISBLANK ( PrevTestDate ),
    'Table'[Score] - 
    CALCULATE( 
        MAX ( 'Table'[Score] ), 
        ALL( 'Table' ), 
        'Table'[StudentID] = CurrStudent, 
        'Table'[TestDate] = PrevTestDate 
    )
)

testscore.jpg

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

Hello @rishtin 

Give this a try.

Score Change = 
VAR CurrStudent = 'Table'[StudentID]
VAR CurrDate = 'Table'[TestDate]
VAR PrevTestDate = 
CALCULATE( 
    MAX ( 'Table'[TestDate] ), 
    ALL ( 'Table' ), 
    'Table'[StudentID] = CurrStudent, 
    'Table'[TestDate] < CurrDate
)
RETURN
IF ( 
    NOT ISBLANK ( PrevTestDate ),
    'Table'[Score] - 
    CALCULATE( 
        MAX ( 'Table'[Score] ), 
        ALL( 'Table' ), 
        'Table'[StudentID] = CurrStudent, 
        'Table'[TestDate] = PrevTestDate 
    )
)

testscore.jpg

Hi @jdbuchanan71 

It worked perfectly.

Highly appreciate this.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.