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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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
 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.