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

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

Reply
afaherty
Helper V
Helper V

Should be easy, but still learning DAX

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 IDGradeCity
1SophomoreAlbany
1SophomoreAlbany
1SophomoreAlbany
2SophomoreTallahassee
3SophomorePittsburgh
4SophomoreRichmond
5SophomoreRichmond
6JuniorPittsburgh
7JuniorTallahassee
7JuniorTallahassee
8JuniorRichmond
9JuniorRichmond
10JuniorAlbany
10JuniorAlbany
11JuniorPittsburgh
12JuniorTallahassee
12JuniorTallahassee
12JuniorTallahassee
13JuniorAlbany
13JuniorAlbany
14JuniorPittsburgh
15JuniorRichmond
16SeniorTallahassee
17SeniorPittsburgh
17SeniorPittsburgh
18SeniorAlbany
18SeniorAlbany
19SeniorRichmond
20SeniorTallahassee
21SeniorRichmond
22SeniorAlbany
22SeniorAlbany
23SeniorRichmond

 

Thank you to anyone who can help.

1 ACCEPTED SOLUTION

@afaherty 

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)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

9 REPLIES 9
smpa01
Super User
Super User

@afaherty  can you please create new thread and post the representative pbix please?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
smpa01
Super User
Super User

@afaherty  try this

Measure = CALCULATE(DISTINCTCOUNT('Table'[Student ID]),ALLEXCEPT('Table','Table'[Grade],'Table'[City]))

 

smpa01_0-1640018393007.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@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

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

<Redacted>

@afaherty  please walk me through  how are you getting the following?

 

smpa01_0-1640020686281.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 

Apologies, had a small miscalc.

Here is what it would be for the Juniors:

 

afaherty_0-1640021450129.png

Sophomores:

 

afaherty_2-1640021601872.png

 

Seniors:

 

afaherty_1-1640021537200.png

 

 

@afaherty 

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)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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?

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.