Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi All,
I think this should be easy, but I'm still learning the ins & outs of DAX and I'm struggling.
I have this unpivoted data, and need to create a bar graph the % of unique students in each grade in each city (grade will be on the legend, city on the slicer). I already have a matrix of the total number of unique students which I achieved easily with DISTINCTCOUNT of IDs, but I'm struggling with the % of unique students by city:
Student ID | Grade | City |
1 | Sophomore | Albany |
1 | Sophomore | Albany |
1 | Sophomore | Albany |
2 | Sophomore | Tallahassee |
3 | Sophomore | Pittsburgh |
4 | Sophomore | Richmond |
5 | Sophomore | Richmond |
6 | Junior | Pittsburgh |
7 | Junior | Tallahassee |
7 | Junior | Tallahassee |
8 | Junior | Richmond |
9 | Junior | Richmond |
10 | Junior | Albany |
10 | Junior | Albany |
11 | Junior | Pittsburgh |
12 | Junior | Tallahassee |
12 | Junior | Tallahassee |
12 | Junior | Tallahassee |
13 | Junior | Albany |
13 | Junior | Albany |
14 | Junior | Pittsburgh |
15 | Junior | Richmond |
16 | Senior | Tallahassee |
17 | Senior | Pittsburgh |
17 | Senior | Pittsburgh |
18 | Senior | Albany |
18 | Senior | Albany |
19 | Senior | Richmond |
20 | Senior | Tallahassee |
21 | Senior | Richmond |
22 | Senior | Albany |
22 | Senior | Albany |
23 | Senior | Richmond |
Thank you to anyone who can help.
Solved! Go to Solution.
Measure =
VAR _num = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade],'Table'[City]))
VAR _denom = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade]))
RETURN DIVIDE(_num,_denom)
@afaherty can you please create new thread and post the representative pbix please?
@afaherty try this
Measure = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade],'Table'[City]))
@smpa01 Hi! Thank you, you always come to my rescue! I had already gotten the totals, but now I need to figure out the percentages which is where I'm stuck! 😓
@afaherty please provide the desired output for the given data
<Redacted>
@afaherty please walk me through how are you getting the following?
Apologies, had a small miscalc.
Here is what it would be for the Juniors:
Sophomores:
Seniors:
Measure =
VAR _num = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade],'Table'[City]))
VAR _denom = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade]))
RETURN DIVIDE(_num,_denom)
Thank you @smpa01! Worked like a charm. I'm having a separate issue though where my slicer (which is "City") isn't working for the new matrix created with your measure. It's showing me all of the cities instead of whichever one I choose. All of the other visuals on the report canvas are complying with the slicer. Any ideas?
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
8 |
User | Count |
---|---|
13 | |
12 | |
11 | |
10 | |
8 |