Forum Discussion

CityCat35's avatar
CityCat35
Frequent Visitor
2 years ago
Solved

Lookup values from one table based on calculated result from another table

I have two tables. The first is a list of all the test scores of my students for each class I teach:

 

StudentCourseTest Result
BobbyScience92
SarahMath99
TimEnglish100
BobbyScience86
SarahMath77
TimEnglish80
BobbyScience61
SarahMath60
TimEnglish70

 

Each course has its own grading system. The second table displays the cutpoints used to determine their letter grade.

CourseMinMaxGrade
Science87100A
Science7586B
Science6274C
Science4461D
Science043F
Math83100A
Math7682B
Math8166C
Math5465D
Math053F
English85100A
English7584B
English6274C
English6144D
English043F

 

I'm using a matrix visual to display the average test results by student/course, and I also want to automatically show the letter grade based on the average results--but I'm stuck. Is there a way to find the grade based on the class and average score?

 

  • Hi CityCat35 

    To bring both data together, you'll most likely would need a third table to bridge the two together. There are more than one grade per course, and there are multiple students per course.


    By the way, your Grade table has some inconsistencies. Min and Max are swapped on some rows.

    You'll then link the two together via relationships. Do take note of the cross-filter direction on one line (not needed at the moment but I do suspect you may want to eventually use it down the line for another evaluation)

     

    Create your average test score measure:

     

    Course.Avg.Number = AVERAGE(StudentScores[Test Result])

     

     

    And then finally in another measure, based on the average, return your grade label:

     

    Course.Avg.Grade = 
    VAR _Number = [Course.Avg.Number]
    RETURN
    CALCULATE(MAX(Grading[Grade]), _Number >= Grading[Min] && _Number <= Grading[Max] )

     

     
    Your output should look like this:

     

2 Replies

  • Hi CityCat35 

    To bring both data together, you'll most likely would need a third table to bridge the two together. There are more than one grade per course, and there are multiple students per course.


    By the way, your Grade table has some inconsistencies. Min and Max are swapped on some rows.

    You'll then link the two together via relationships. Do take note of the cross-filter direction on one line (not needed at the moment but I do suspect you may want to eventually use it down the line for another evaluation)

     

    Create your average test score measure:

     

    Course.Avg.Number = AVERAGE(StudentScores[Test Result])

     

     

    And then finally in another measure, based on the average, return your grade label:

     

    Course.Avg.Grade = 
    VAR _Number = [Course.Avg.Number]
    RETURN
    CALCULATE(MAX(Grading[Grade]), _Number >= Grading[Min] && _Number <= Grading[Max] )

     

     
    Your output should look like this:

     

  • You can simplify it at least in 2 aspects,

    1. Keep Min only as threshold for each grade bucket;
    2. Use single-direction filtering in *:* relation (in spite of best practice of 1:*)

      

     

     

    For fun only, a showcase of power Excel formulas, (the score in red is to verify the fomula)