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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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