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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Simon_Evans
Helper I
Helper I

How to count number of records based on a value in a measure

Hi All

I'm a bit stuck with what is rather a simple requirement.

 

What I need to do is to end up displaying a single figure on a card visual which is the count of the number of students where there percentage attendance is less than 0.90 (90%). The card visual will be affected by a date slicer. The slicer uses the date field in the SessionAttendance table.

 

Here are my two tables and their relationship

Simon_Evans_0-1680095730417.png

The relationship is joined on the Student ID that exists in both tables.

 

This is a sample of the SessionAttendance Table

DateEmployeeAttendance CodeStudent ID
15/09/2022A546318024A1161584171A1002809422
30/09/2022A546318024A1161584171A1002809422
22/09/2022A546318024A1161584171A1002809422
23/09/2022A546318024A1161584171A1002809422
29/09/2022A546318024A1161584171A1002809422
12/10/2022A546318024A1161584171A1002809422
21/09/2022A546318024A1161584171A1002809422
18/10/2022A546318024A1161584171A1002809422
02/11/2022A546318024A1161584171A1002809422
08/11/2022A546318024A1161584171A1002809422
27/09/2022A546318024A1161584171A1002809422
05/10/2022A546318024A1161584171A1002809422
13/09/2022A546318024A1161584171A1002809422
17/01/2023A546318024A1329183376A1002809422
18/01/2023A546318024A1329183376A1002809422
19/01/2023A546318024A1329183376A1002809422
20/01/2023A546318024A1329183376A1002809422
23/01/2023A546318024A1329183376A1002809422
24/01/2023A546318024A1329183376A1002809422
21/02/2023A546318024A1329183376A1002809422
22/02/2023A546318024A1329183376A1002809422
23/02/2023A546318024A1329183376A1002809422
24/02/2023A546318024A1329183376A1002809422
27/02/2023A546318024A1329183376A1002809422
28/02/2023A546318024A1329183376A1002809422
21/09/2022A546318024A1161584171A1016898777
04/10/2022A546318024A1161584171A1016898777
08/03/2023A546318024A1161584171A1016898777
31/10/2022A546318024A1161584171A1016898777
14/09/2022A546318024A1161584171A1016898777
20/10/2022A546318024A1161584171A1016898777
16/09/2022A546318024A1161584171A1016898777
21/10/2022A546318024A1161584171A1016898777
19/10/2022A546318024A1161584171A1016898777

This is a sample of the Students table

StudentIDGenderDateOfBirthYearCodeRegistrationGroupPartTimeAdmissionDateEthnicityEthnicCode
A1750145926FEMALE12/04/20171OAKNo02/09/2019White - EnglishWENG
A1542680286FEMALE22/09/20161OAKNo02/09/2019White - EnglishWENG
A1249189494MALE05/05/20171ASHNo06/09/2021White - EnglishWENG
A507895988MALE02/05/20171PINENo06/09/2021White - EnglishWENG
A1565350494FEMALE13/07/20171OAKNo06/09/2021White - EnglishWENG
A922796757MALE21/07/20171PINENo06/09/2021White - EnglishWENG
A1235433395MALE20/09/2017RPINENo05/09/2022White - EnglishWENG
A1794198628FEMALE20/05/2018RASHNo05/09/2022White - EnglishWENG
A1511763796MALE17/10/2017RPINENo05/09/2022White - EnglishWENG
A1999965237FEMALE03/12/2017RASHNo05/09/2022White - EnglishWENG
A1433408704MALE15/02/20171ASHNo02/09/2019White - EnglishWENG
A1350601327MALE21/05/20171ELMNo06/09/2021White - EnglishWENG
A1002809422MALE15/06/201533TONo02/09/2019White - EnglishWENG
A317854122FEMALE20/12/201433TONo02/09/2019White - EnglishWENG
A619309687FEMALE21/04/201533TONo02/09/2019White - EnglishWENG
A1293808694MALE15/02/201355BBNo01/09/2017White - EnglishWENG
A392403471MALE07/11/201433CBNo01/09/2017White - EnglishWENG
A1234098928MALE12/05/201533CBNo02/09/2019White - EnglishWENG
A687256901MALE19/02/201533TONo02/09/2019White - EnglishWENG
A1984655952FEMALE20/11/20161OAKNo03/09/2020White - EnglishWENG
A90208359FEMALE02/01/201444SLNo01/09/2016White - EnglishWENG
A122545299FEMALE28/06/2018ROAKNo05/09/2022White - EnglishWENG
A1803153734MALE16/07/20171ELMNo06/09/2021White - EnglishWENG
A1832738044MALE17/04/201533CBNo01/09/2018White - EnglishWENG
A670724717FEMALE03/02/201533TONo02/09/2019White - EnglishWENG
A790338908MALE16/10/2017ROAKNo06/09/2021White - EnglishWENG
A1821313148FEMALE14/06/201444ESNo01/09/2017White - EnglishWENG

 

I have the following DAX measure on the SessionAttendance table which calculates the percentage attendance by counting the appropriate codes for present and then dividing that by the count of the possible attendances codes. The result is a decimal figure.

 

 

Pupil % Attendance = 
var _PossSessions = CALCULATE(COUNTROWS(SessionAttendance),SessionAttendance[Attendance Code]<>"A930902628" && SessionAttendance[Attendance Code]<>"A1801476586" && SessionAttendance[Attendance Code]<>"A1131916182" && SessionAttendance[Attendance Code]<>"A1299388415" && SessionAttendance[Attendance Code]<>"A1462380788" && SessionAttendance[Attendance Code]<>"" && SessionAttendance[Attendance Code]<>"A124965801" && SessionAttendance[Attendance Code]<>"A493975360" && SessionAttendance[Attendance Code]<>"A795820045" && SessionAttendance[Attendance Code]<>"A627303844" && SessionAttendance[Attendance Code]<>"A996587839" && SessionAttendance[Attendance Code]<>"A323305093" && SessionAttendance[Attendance Code]<>"A700043804")

var _PresentMarks = CALCULATE(COUNTROWS(SessionAttendance),SessionAttendance[Attendance Code]="A1329183376" || SessionAttendance[Attendance Code]= "A1161584171" || SessionAttendance[Attendance Code]="A830070477" || SessionAttendance[Attendance Code]="A186523258" || SessionAttendance[Attendance Code]="A1529934786"|| SessionAttendance[Attendance Code]="A319327454"|| SessionAttendance[Attendance Code]="A1500139297"|| SessionAttendance[Attendance Code]="A1601102008")

Return
_PresentMarks / _PossSessions

 

When I use the above measure in a table along with the Students name I get the % attendance for each student so I know the measure works.

 

What I am now stuck on is how to combine this measure with a count and filter DAX expression to get the count of Students where the % attendance in the measure is less than 0.90. Can anyone assist please?

 

Kindest regards

Simon

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Simon_Evans 

please try

Count > 90% =
SUMX ( VALUES ( Students[StudentID] ), INT ( [Pupil % Attendance] > 0.9 ) )

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Simon_Evans 

please try

Count > 90% =
SUMX ( VALUES ( Students[StudentID] ), INT ( [Pupil % Attendance] > 0.9 ) )

@tamerj1 Thank you once again. Don't worry about why it was miss counting. I think that is something within the test dataset I am using as I have tried this on a non live version of a customers data set and it is working perfectly!

@tamerj1 

Thank you so much. Cannot believe it was such a short DAX measure. 

 

However it appears the formula is counting more than it should which Im struggling to work out why as I can put it alongside a table with the studentIDs and the percentage attendance.

 

Simon_Evans_0-1680101000853.png

This is what I have. For the date range of the slicer you can see that the formula comes back with a count of 7 but according to the table it should be 6.

I slightly tweaked the formula to the below.

Count Less than 90% = SUMX(VALUES(Students[WondeStudentID]),INT([Pupil % Attendance]<=0.9))

 

Any ideas as to why it is over counting at all please?

I believe you must use the below one to get correct count:

Count Less than 90% = SUMX(VALUES(Students[WondeStudentID]),INT([Pupil % Attendance]< 0.9))

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.