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
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
Employee
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
Employee
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
Super User
Super User

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


@ 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!:
The Definitive Guide to Power Query (M)

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
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.