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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
afaherty
Helper V
Helper V

Counts & Percentages for Non-Numerical Data

Hello,

Can someone help me figure this out?  This is all fake data but is set up in the same manner as my real data.

This is unpivoted:

 

IDGraduation YearMajorsCity
12020EducationBaltimore
12020SpanishBaltimore
12020PsychologyBaltimore
22019PsychologyChicago
32019EducationPhiladelphia
32019SpanishPhiladelphia
42020EducationMadison
42020SpanishMadison
42020HistoryMadison
52019EducationAthens
62019EducationAlbuquerque
62019SpanishAlbuquerque
72020EducationTampa
72020SpanishTampa
72020HistoryTampa
82019EducationNewport News
92019EducationDover
92019SpanishDover
102020HistorySacramento
112020EducationBaltimore
112020SpanishBaltimore
122019HistoryChicago
132019HistoryChicago
132019EducationChicago

 

1.)  What I need to do is first find the totals and there will be a slicer for city.   

afaherty_0-1639689647250.png

2.)  Secondly, I need to find the percentages of majors by city (city will still be the slicer) by graduation year.  So, for example, for Chicago, the % of Psychology majors is 33%.  For Chicago, the % of history majors is 67%.  

 

I hope that makes sense.  Thanks to anyone who can help!

 

1 ACCEPTED SOLUTION

@afaherty  please give this a try and let me know if this gives you what you need

 

Measure = 
VAR _numerator =
    DISTINCTCOUNT ( 'Table 1'[ID] )
VAR _selectedCity =
    ALLSELECTED ( 'Table 1'[City] )
VAR _denominator =
    CALCULATE (
        DISTINCTCOUNT ( 'Table 1'[ID] ),
        TREATAS ( _selectedCity, 'Table 1'[City] ),
        REMOVEFILTERS ( 'Table 1'[Majors] )
    )
RETURN
    DIVIDE ( _numerator, _denominator )

 

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

View solution in original post

17 REPLIES 17
smpa01
Super User
Super User

@afaherty please walk me through how are you getting 50% for Baltimore-Psychology-2019 given the above 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

Ah so sorry, I must have been staring at it for far too long.  I edited the post to say: "for Chicago, the % of Psychology majors is 33%."  I always attempt to google my question before coming here, and I think I just got all mixed up after reading so much.

@afaherty  this is Chicago

 

smpa01_0-1639771033086.png

why Psychology is 33% and History is 67%

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 Yes, perfect!  What is the DAX to produce the percentages?  I will be creating a bar graph of the percentages.  Thank you!

@afaherty  So Psychology for Chicago-2019 should be 25% (1/4) and History for Chaicago-2019 should be 50%(2/4) ...Do you agree?

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 Ah, so Psychology is 33% because 1 person out of 3 majored in Psychology (as shown by their ID).  History is 67% because 2 people out of 3 majored in history.  (For the sake of my example, we'll say that some people had double-majors).

@afaherty  please give this a try and let me know if this gives you what you need

 

Measure = 
VAR _numerator =
    DISTINCTCOUNT ( 'Table 1'[ID] )
VAR _selectedCity =
    ALLSELECTED ( 'Table 1'[City] )
VAR _denominator =
    CALCULATE (
        DISTINCTCOUNT ( 'Table 1'[ID] ),
        TREATAS ( _selectedCity, 'Table 1'[City] ),
        REMOVEFILTERS ( 'Table 1'[Majors] )
    )
RETURN
    DIVIDE ( _numerator, _denominator )

 

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

<Redacted - I made an error, post resolved>

@afaherty  this has been going on for a while. Please start reading it from the beginning.

 

ID Year Major
1 2019 Spanish
1 2019 Education
3 2019 History
4 2019 Education
5 2019 History
5 2019 Education
5 2019 Psychology

 

How many unique ID's do you have ?-4

Spanish - 25% (1/4)

Education - 75% (3/4)

History - 50% (2/4)

Psy - 25% (1/4)

 

It is doing what it is supposed to cause you metioned before on the given data

 

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

I apologize, it is difficult because I am making up this dummy data as I go along.  All I know is that it's not calculating correctly in my actual, real data.  For example, it is telling me that 1/5 is 25% when it should be 20%. It is telling me that 3/5 is 75% when it should be 60%. I apologize for wasting your time.  You have been very helpful.

@afaherty  if the excerpt above is from the real data, then denominator is 4 and not 5. I have clearly explained above why it is 4 cause you previously mentione that it needs to be unique ID.

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

It isn't, it's fake - the real denominator is 5.  I will attempt to figure it out.  Thanks again,

<Redacted - I made an error, post resolved>

@afaherty  provide the screenshot from your end of the measure and the viz

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
afaherty
Helper V
Helper V

Maybe @smpa01 ?  

Been attempting this for a couple of days now. 😓  Sincerely thank everyone for their help.

VahidDM
Super User
Super User

Hi @afaherty 

 

For the first question you can use the Matrix visual and set it as below:

VahidDM_0-1639691813119.png

 

 

For the second question use this measure:

Measure =
Var _A = count('Table'[ID])
Var _B = CALCULATE(count('Table'[ID]),REMOVEFILTERS('Table'[City]))
return
_A/_B
 
 
download this file:
 
 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/


 

@VahidDM Thank you, though it doesn't seem that the measure is working.  It's producing 100% for each row.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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