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
olimilo
Responsive Resident
Responsive Resident

Getting the most recent and second most recent values by group (without dates)

Hi everyone,

 

I'm trying to get the most recent and second most recent values in my table. I've looked up several examples on here, but the my data doesn't have a date value to check the most recent value with, although I can use a TestID to check the chronological order of the data with (eg: lower TestID means this was done earlier).

 

Any suggestion on how I can go about with this?

 

StudentIDTestCodeTestIDRating
Student0061Test0000229947092.54
Student0061Test0000231861038.15
Student0061Test0000331861054
Student0061Test0000631861043.91
Student0062Test0000331091289
Student0062Test0000332451289
Student0063Test0001130187646.63
Student0063Test00011311438100
Student0064Test0000329687396
Student0065Test0000531137196.82
Student0066Test0000330731175
Student0066Test0000330834477
Student0066Test0000332106874

 

StudentIDTestCodeMost Recent2nd Most Recent
Student0061Test0000238.1592.54
Student0061Test0000354 
Student0061Test0000643.91 
Student0062Test000038989
Student0063Test0001110046.63
Student0064Test0000396 
Student0065Test0000596.82 
Student0066Test000037477
1 ACCEPTED SOLUTION

@olimilo solution attached, look at table2 and page 3 in attached.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@olimilo here are two measures which would work

 

Most Recent = 
CALCULATE( 
    MAX( Table2[Rating] ), 
    FILTER( 
        ALLEXCEPT( Table2, Table2[StudentID], Table2[TestCode] ), 
        Table2[Index] = MAX( Table2[Index] ) 
    ) 
) 

Most Recent 2 = 
CALCULATE( 
    MAX( Table2[Rating] ), 
    FILTER( 
        ALLEXCEPT( Table2, Table2[StudentID], Table2[TestCode] ), 
        Table2[Index]=  MAX( Table2[Index] ) - 1 
    )
) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

olimilo
Responsive Resident
Responsive Resident

Hi @parry2k 

 

Thank you, but unfortunately both measures didn't work for me. Also, using an Index - 1 filter for the 2nd most recent took data from other students and other test codes.

 

@olimilo I think I missed to point out that you need to add index field using query editor. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@olimilo solution attached, look at table2 and page 3 in attached.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.