Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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

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

     

    Or a calculated column

     

    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:

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

     

1 Reply

  • m_dekorte's avatar
    m_dekorte
    Icon for Resident Rockstar rankResident Rockstar

    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.

     

    Or a calculated column

     

    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:

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