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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dphillips
Helper IV
Helper IV

Count of students in a subject

I have a table of students in different subjects (Assessment Code). How do I get the total number of students in each Assessment Code for each Fileyear and Filesemester?

 

If I was doing this in TSQL I could do

 

Count(R.Id) over (partition by R.Fileyear,R.FileSemester,R.Assessmentcode) as StudCount,

 

How do I do this in PowerBI in DAX? Do I use a measure or calculated column? I am assuming a calculated column but not sure how to go about partitioning the count over the Fileyear, Filesemester and AssessmentCode.

 

Any help appreciated.

 

Count of Students.JPG

 

 

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @dphillips,

 

You can create a calculated column similar to below:

Count student =
CALCULATE (
    COUNT ( table[ID] ),
    ALLEXCEPT ( table, table[Assessmentcode], table[Fileyear], table[FileSemester] )
)

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @dphillips,

 

You can create a calculated column similar to below:

Count student =
CALCULATE (
    COUNT ( table[ID] ),
    ALLEXCEPT ( table, table[Assessmentcode], table[Fileyear], table[FileSemester] )
)

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks - works well.

Greg_Deckler
Community Champion
Community Champion

Typicall you would just create a table or matrix visualization with your Assessment Code, Fileyear and Filesemester in it and a Count of some other field. 

 

Sample data that can be copied and pasted is always more helpful than screen shots. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks for the heads up regarding data. I have a pbix file to show you but not sure how I can attach this. Can you let me know how as I can't see anywhere to attache the data.

 

I can easily get a count of the students but my problem occurs when I use a slicer to select just one student to see his results. By filtering the data, the number of students in each subject is, obviously 1.  How do I get the total number of students in each subject even when I have selected only 1 student in a slicer?

 

Happy to send the data if you could help on the best way of doing this. Thanks for your help.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors