Forum Discussion

afaherty's avatar
afaherty
Icon for Helper V rankHelper V
4 years ago
Solved

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.   

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!

 

  • smpa01's avatar
    smpa01
    4 years ago

    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 )

     

     

17 Replies

  • Hi afaherty 

     

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

     

     

    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/


     

    • afaherty's avatar
      afaherty
      Icon for Helper V rankHelper V

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

  • Maybe smpa01 ?  

    Been attempting this for a couple of days now. ğŸ˜“  Sincerely thank everyone for their help.

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    afaherty please walk me through how are you getting 50% for Baltimore-Psychology-2019 given the above data ?

    • afaherty's avatar
      afaherty
      Icon for Helper V rankHelper V

      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.

      • smpa01's avatar
        smpa01
        Icon for Community Champion rankCommunity Champion

        afaherty  this is Chicago

         

        why Psychology is 33% and History is 67%