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

Top Solution Authors
Top Kudoed Authors