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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
botaac
Frequent Visitor

Input the most recent teacher with DAX

Hi Everyone,

 

I have the following data.

Student NameTeacherGrade
Bob SmithPhil Seger8th grade
Bob SmithCraig Steven9th grade
Bob SmithTeresa White10th grade
Jim DoeLarry Daniels8th grade
Jim DoeRoger Hall9th grade
Jim DoeLinda Lou10th grade

 

I want to create an additional column with DAX that would pull the most recent teacher. Therefore, the table would look like:

 

Student NameTeacherGradeMost Recent Teacher
Bob SmithPhil Seger8th gradeTeresa White
Bob SmithCraig Steven9th gradeTeresa White
Bob SmithTeresa White10th gradeTeresa White
Jim DoeLarry Daniels8th gradeLinda Lou
Jim DoeRoger Hall9th gradeLinda Lou
Jim DoeLinda Lou10th gradeLinda Lou

 

How would I go about setting this up in DAX?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, 

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Most Recent Teacher CC =
VAR currentstudent = Data[Student Name]
VAR addgradenumber =
ADDCOLUMNS (
FILTER ( Data, Data[Student Name] = currentstudent ),
"@gradenumber", INT ( LEFT ( Data[Grade], SEARCH ( "th", Data[Grade] ) - 1 ) )
)
VAR lastgrade =
MAXX ( addgradenumber, [@gradenumber] )
VAR newtable_teachername =
SUMMARIZE (
FILTER ( addgradenumber, [@gradenumber] = lastgrade ),
Data[Teacher]
)
RETURN
newtable_teachername
 


Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question





View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
smpa01
Super User
Super User

@botaac  in case you needed a measure

_mostRecentTeacher = 
CALCULATE (
    CALCULATE (
        MAX ( t2[Teacher] ),
        FILTER (
            t2,
            CONVERT ( SUBSTITUTE ( t2[Grade], "th grade", "" ), INTEGER )
                = MAXX (
                    FILTER ( t2, EARLIER ( t2[Student Name] ) = t2[Student Name] ),
                    CONVERT ( SUBSTITUTE ( t2[Grade], "th grade", "" ), INTEGER )
                )
        )
    ),
    ALLEXCEPT ( t2, t2[Student Name] )
)

 

smpa01_0-1637786164928.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Jihwan_Kim
Super User
Super User

Hi, 

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Most Recent Teacher CC =
VAR currentstudent = Data[Student Name]
VAR addgradenumber =
ADDCOLUMNS (
FILTER ( Data, Data[Student Name] = currentstudent ),
"@gradenumber", INT ( LEFT ( Data[Grade], SEARCH ( "th", Data[Grade] ) - 1 ) )
)
VAR lastgrade =
MAXX ( addgradenumber, [@gradenumber] )
VAR newtable_teachername =
SUMMARIZE (
FILTER ( addgradenumber, [@gradenumber] = lastgrade ),
Data[Teacher]
)
RETURN
newtable_teachername
 


Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question





Thank you for your assistance! This worked great, best wishes and be safe out there.

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

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