The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi DAX champions,
I am trying to calculate/write a measure for the different categories/labels/legend in a stacked bar chart.
My table/data looks something like this:-
I have student grades across multiple semesters. If I simply do an aggregate/count of student grades across semesters, it looks something like this (semester_code 202410 translates to 2023/2024 Fall) :-
The semester code values are 201710, 201720, 201730, 201810, 201820,...,202330, 202410, 202420.
When looking at the tooltip, it looks like this:-
I want to write a DAX measure such that I can view the correct percentage (for the above scenario, 40.27%).
This is what I have written:-
Student percent per Grade group =
var student_total_per_term = CALCULATE(COUNT('Course Grade'[student_id]), ALLEXCEPT('Course Grade', 'Course Grade'[semester_code]))
return DIVIDE(COUNT('Course Grade'[course_grade (groups)]), student_total_per_term)
I am not sure where I am going wrong and I would appreciate your help 🙂
Regards,
Sarthak
Solved! Go to Solution.
Hi @sarthakgirdhar ,
Regarding your question, you are not using the column 'semeter_code' in your visual, so the filtering effect of keeping this column has no effect.
Change the column name to the one I marked.
For "202410", the correct value is 22.
Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @sarthakgirdhar ,
Regarding your question, you are not using the column 'semeter_code' in your visual, so the filtering effect of keeping this column has no effect.
Change the column name to the one I marked.
For "202410", the correct value is 22.
Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous / Wenbin Zhou,
Thank you for taking the time to provide the solution. I am using a star schema and I was under the impression that the semester_code description would automatically be picked up, but apparently that's not the case.
I will take it from here. Thank you for your help 🙂
Kind regards,
Sarthak
User | Count |
---|---|
26 | |
10 | |
8 | |
6 | |
6 |
User | Count |
---|---|
31 | |
12 | |
10 | |
10 | |
9 |