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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SPaine86
Helper I
Helper I

Working out percentage from a measure in a related table

Hi there!

 

I am trying to work out the percentage of pupils who have attendance at, or below, 90% using a measure.

 

The attendance table ('Attendance list') looks like this:

UIDYearTermPresent + AEAPossible
PupilA1232021Term 16165
PupilA1232021Term 25965
PupilA2342021Term 16165
PupilA2342021Term 26565
PupilB1252021Term 14165

 

It is filtered in Power Query so that no pupil has null or 0 Possible attendance.

 

I have a corresponding table called 'Pupils', which has a one to many relationship with the Attendance List (each pupil can have multiple entries in Attendance list). I also have a table called 'Pupil Characteristics', which has a many to one relationship with Pupils (each pupil can have multiple characteristics) with the filter direction going both ways.

 

The measure I've created doesn't seem to work as I anticipated. I need it to:

  • For each pupil, work out their attendance (by dividing the sum of [Present + AEA] by the sum of [Possible]), which I have achieved using a measure called [Attendance 2020/21]
  • Filter the pupils who have a result less than or equal to 0.9, and count the number of rows
  • Divide this number by the number of pupils for who we have an attendance record

This is my measure:

 
PA 2021 =
if(isblank(COUNTROWS (
FILTER (
Pupils,
VAR vResults = RELATEDTABLE('Attendance list') RETURN
COUNTROWS (
FILTER (vResults, [Attendance (2020/21)]<=0.9)
) >0
)
)
), 0,
divide( 
COUNTROWS (
FILTER (
Pupils,
VAR vResults = RELATEDTABLE('Attendance list') RETURN
COUNTROWS (
FILTER (vResults, [Attendance (2020/21)]<=0.9)
) >0
)
),
distinctcount('Attendance list'[UID]), 0))
 
This measure is counting someone as persistently absent (i.e. <=90% attendance) if they have at least one incidence of being PA in a term, but I want it to determine whether they are PA by looking at the sum of whatever data is included in the filter. For example, if we are looking at Term 1, Term 2, and Term 3, I was expecting this measure to work out the total Present + AEA and divide this by the Total Possible. Instead, it seems to be working out each term separately - and if one comes back as true then the pupil is included in the filer. My matrix to test the measure looks like this:
 
Name, Attendance [2020/21], PA
Bob Smith, 92%, 100%
Jack Jones, 91%, 0%
 
Drill down>>
Name, Attendance [2020/21], PA
Bob Smith, 92%, 100%
Term 1, 100%, 0%
Term 2, 100%, 0%
Term 3, 95%, 0%
Term 4, 90%, 100%
 
Can anyone see what I've done wrong?
 
Thank you in anticipation!
 
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@SPaine86 , try like

countx(filter(summarize(table,table[UID], table[Year], "_1",divide(sum(Table[Present + AEA]),sum(Table[Possible]))),[_1]>.9),[UID])

 

measure =
var _tab = filter(summarize(table,table[UID], table[Year], "_1",divide(sum(Table[Present + AEA]),sum(Table[Possible]))),[_1]>.9)
return
countx(summarize(_tab,[UID]),[UID])

 

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@SPaine86 , try like

countx(filter(summarize(table,table[UID], table[Year], "_1",divide(sum(Table[Present + AEA]),sum(Table[Possible]))),[_1]>.9),[UID])

 

measure =
var _tab = filter(summarize(table,table[UID], table[Year], "_1",divide(sum(Table[Present + AEA]),sum(Table[Possible]))),[_1]>.9)
return
countx(summarize(_tab,[UID]),[UID])

 

 

Thank you, I did a minor tweaks to the code (e.g. >.9 is <=0.9) and it seems to be working nicely!

I didn't realise you could create a virtual table like this. Opens up a world of possibility...

 

Thank you again 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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