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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
CityCat35
Frequent Visitor

Calculate Average if Denominator Meets Certain Critieria

Teachers at a special needs school are evaluated based on the performance of their students. Here's how it works:

  • Each student has all of their test scores averaged, which computes to a letter score (i.e., think A, B, C, D, F)
  • Student grades are averaged to give teachers a score between 1 and 5 (i.e., A=5, B=4, C=3, D=2, F=1)
  • Kids are absent all the time, so if the children haven't completed enough work, they don't get a grade.
  • For a teacher to get evaluated, at least half of their students have to have a letter grade

 

Problem: I need a formula that will only calculate a teacher's evaluation score IF at least half of her students have a letter grade. Otherwise, she would be evaluated as "Not Enough Information." Is there a DAX formula for this scenario. Sample data is below

 

Average GradeEvaluation Score
F1
D2
C3
B4
A5

 

TeacherStudentAverage Grade
Ms. JohnsonJamesA
Ms. JohnsonMollyC
Ms. JohnsonAveryA
Ms. JohnsonJackB
Ms. JohnsonBillyNo Grade
Ms. JohnsonPennyA
Ms. JohnsonScottC
Ms. JohnsonWillowNo Grade
Ms. JohnsonJenniferA
Ms. JohnsonThomasNo Grade
Mr. AllenGraceB
Mr. AllenAidenNo Grade
Mr. AllenTylerA
Mr. AllenDallasNo Grade
Mr. AllenOliverNo Grade
Mr. AllenBaileyNo Grade
Mr. AllenOliviaNo Grade
Mr. AllenChrisA
Mr. AllenQuinnC
Mr. AllenAlexNo Grade
1 ACCEPTED SOLUTION
RossEdwards
Solution Sage
Solution Sage

For my solution i would suggest merging the 2 tables into one.  You can do this with the "Merge Queries" in Power Query.  This would mean you should have two columns now, an Average Grade and Evaluation Score in your main table.

 

First we need a measure to figure out if a teacher should be considered:

Valid Data = VAR noGradeRows = CALCULATE(
    COUNTROWS('YourTable'),
    'YourTable'[Average Grade] = "No Grade"
)
VAR allRows = COUNTROWS('YourTable')
RETURN
DIVIDE(noGradeRows, allRows) <= 0.5  // This measure will return either TRUE or FALSE

 

Now we need a measure that calculates the average grade

Average Grade = CALCULATE(
    AVERAGE('YourTable'[Evaluation Score]),
    NOT 'YourTable'[Average Grade] = "No Grade"
)

 

From here, if you create a table visual, with the first column being the teacher and the last column being the following measure:

Teacher Grade = VAR selectedTeacher = SELECTEDVALUE('YourTable'[Teacher])
VAR validData = IF(   // Does a check that only a single teacher is selected and that teacher has valid data
    ISBLANK(selectedTeacher),
    FALSE(),
    [Valid Data]
)
VAR result = IF(
    validData,
    [Average Grade],
    0
)
VAR output = SWITCH(
    INT(result),  // Round down the average grade
    0, "Not Enough Information.",
    1, "F",
    2, "D",
    3, "C",
    4, "B",
    5, "A"
)
RETURN
output

View solution in original post

1 REPLY 1
RossEdwards
Solution Sage
Solution Sage

For my solution i would suggest merging the 2 tables into one.  You can do this with the "Merge Queries" in Power Query.  This would mean you should have two columns now, an Average Grade and Evaluation Score in your main table.

 

First we need a measure to figure out if a teacher should be considered:

Valid Data = VAR noGradeRows = CALCULATE(
    COUNTROWS('YourTable'),
    'YourTable'[Average Grade] = "No Grade"
)
VAR allRows = COUNTROWS('YourTable')
RETURN
DIVIDE(noGradeRows, allRows) <= 0.5  // This measure will return either TRUE or FALSE

 

Now we need a measure that calculates the average grade

Average Grade = CALCULATE(
    AVERAGE('YourTable'[Evaluation Score]),
    NOT 'YourTable'[Average Grade] = "No Grade"
)

 

From here, if you create a table visual, with the first column being the teacher and the last column being the following measure:

Teacher Grade = VAR selectedTeacher = SELECTEDVALUE('YourTable'[Teacher])
VAR validData = IF(   // Does a check that only a single teacher is selected and that teacher has valid data
    ISBLANK(selectedTeacher),
    FALSE(),
    [Valid Data]
)
VAR result = IF(
    validData,
    [Average Grade],
    0
)
VAR output = SWITCH(
    INT(result),  // Round down the average grade
    0, "Not Enough Information.",
    1, "F",
    2, "D",
    3, "C",
    4, "B",
    5, "A"
)
RETURN
output

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 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.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors