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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Creating a Custom Column to Show Instances of Primary Key

I have a number of students who have taken several classes on our educatonal platform. I have separate pages that shows the demographic breakdown of each class and another page that shows the demographic breakdown across all classes. I am trying to see if there is a way to create a column or organize my data so that I can show a breakdown of the number (and ideally names) of classes students have taken. As an example my raw data looks like this:

Student IDClass YearCourse
S001FreshmanMath
S002SophomoreMath
S003JuniorMath
S004SeniorMath
S003JuniorPhysics
S004SeniorPhysics
S005SeniorPhysics
S001FreshmanChemistry
S002SophomoreChemistry
S005SeniorPhysics
S006JuniorChemistry
S007JuniorChemistry
S004SeniorEconomics
S008JuniorEconomics
S009JuniorEconomics
S010SophomoreEconomics

 

The one idea I had was to do a count that would look something like this:

Student IDNumber of Courses
S0012
S0022
S0032
S0043
S0052
S0061
S0071
S0081
S0091
S010

1

But aside from not knowing how to do that in DAX (question #1!) I would ideally want to use this "number of classes" into a slicer--or perhaps add relationship for when people clicked on a visual--that would show how the breakdown of Fresh/Soph/Junior/Senior changed for students that took, for example, 3 classes (and which 3 they were).

 

Thank you in advance

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @Anonymous,

 

For a slicer you need a column with the Class count in your table.

You can achieve this in Power Query, leveraging the Group By transformation. After the count has been added you can bring back the other fields by using the expand column option, the sideward arrows in the column header.

m_dekorte_1-1684735180131.png

 

Or a calculated column

m_dekorte_0-1684735148213.png

 

With a simple rowcount, and depending on what you bring into your visual you'll see a break down of that number by the selected attributes. For example:

m_dekorte_2-1684735404126.png

Ps. If this helps solve your query please mark this post as Solution, thanks!

 

View solution in original post

1 REPLY 1
m_dekorte
Super User
Super User

Hi @Anonymous,

 

For a slicer you need a column with the Class count in your table.

You can achieve this in Power Query, leveraging the Group By transformation. After the count has been added you can bring back the other fields by using the expand column option, the sideward arrows in the column header.

m_dekorte_1-1684735180131.png

 

Or a calculated column

m_dekorte_0-1684735148213.png

 

With a simple rowcount, and depending on what you bring into your visual you'll see a break down of that number by the selected attributes. For example:

m_dekorte_2-1684735404126.png

Ps. If this helps solve your query please mark this post as Solution, thanks!

 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors