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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
afaherty
Helper V
Helper V

Help: percentage of row totals with categorical data

Hello,

I have spent many hours attempting to solve this issue but have been unsuccessful.

Here is some dummy data similar to my actual data:

 

StudentIDCompetitionRating
1DecimalsAbove Average
1FractionsAverage
1EquationsBelow Average
1Essay WritingAverage
1ThesisAverage
1Outline PrepBelow Average
2DecimalsAbove Average
2FractionsAbove Average
2EquationsAverage
2Essay WritingBelow Average
2ThesisBelow Average
2Outline PrepAverage
3DecimalsAverage
3FractionsBelow Average
3EquationsAverage
3Essay WritingAbove Average
3ThesisAverage
3Outline Prep

Above Average

4Decimals

Below Average

4Fractions

Below Average

4Equations

Below Average

4Essay Writing

Average

4Thesis

Average

4Outline Prep

Average

5Decimals

Above Average

5Fractions

Above Average

5Equations

Above Average

5Essay Writing

Average

5Thesis

Below Average

5Outline Prep

Average

 

If I get the total of distinct students with N = DISTINCTCOUNT(StudentID) and then I place that measure into the Values section twice, and then tell PowerBI to take the 2nd instance of the measure and show me the % of row total, then it looks great. However, the problem is that I want a DAX measure for this - I do not want to rely on choosing the option for it to show me the % of row total. Every DAX formula I have tried produces 100% all the way down each % column. I am waving my white flag! Thank you to anyone who can help!

 

PBI.png

2 ACCEPTED SOLUTIONS

@afaherty 

 

Hi, you may update the measure to below to isolate the row-level total.

DIVIDE( DISTINCTCOUNT(StudentRatings[StudentID]), 
CALCULATE( DISTINCTCOUNT(StudentRatings[StudentID]), 
REMOVEFILTERS(StudentRatings[Rating]), ALLSELECTED() ) )   

 

View solution in original post

@FBergamaschi I am rather confused now because this morning when I used the code from MasonMA that I now see above it did not work and I got 100% all the way down the column:

VAR CurrentCount =
    DISTINCTCOUNT(StudentRatings[StudentID])

VAR TotalCount =
    CALCULATE(
        DISTINCTCOUNT(StudentRatings[StudentID]),
        REMOVEFILTERS(StudentRatings[Rating])
    )
RETURN
DIVIDE(CurrentCount, TotalCount, 0)

However, when I look at the email notification I received when MasonMA replied to my post, here is what his response said:

 

Screenshot 2025-07-23 091219.jpg

That code mentioned in the picture above is what worked, but I no longer see this post from MasonMA in this thread at all. 

 

So, in conclusion, here is what did work:

DIVIDE( DISTINCTCOUNT(StudentRatings[StudentID]), 
CALCULATE( DISTINCTCOUNT(StudentRatings[StudentID]), 
REMOVEFILTERS(StudentRatings[Rating]), ALLSELECTED() ) )   

View solution in original post

7 REPLIES 7
FBergamaschi
Solution Sage
Solution Sage

The code should be

 

DIVIDE ( 
           N,
           CALCULATE ( N, REMOVEFILTERS ( Rating ) )
)

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Hi @FBergamaschi ,

Thank you so very much. Your solution worked perfectly in my dummy PowerBI file. However, in my real file (which I can't post here), it's still producing 100%'s all the way down each rating column. I do have slicers for multiple variables, but I think that shouldn't matter. I am so confused!

@afaherty 

 

Hi, you may update the measure to below to isolate the row-level total.

DIVIDE( DISTINCTCOUNT(StudentRatings[StudentID]), 
CALCULATE( DISTINCTCOUNT(StudentRatings[StudentID]), 
REMOVEFILTERS(StudentRatings[Rating]), ALLSELECTED() ) )   

 

This worked in my real dataset! Thank you so much! 

Ciao @afaherty 

 

just to be sure I get the thing

 

my code

DIVIDE ( 
           N,
           CALCULATE ( N, REMOVEFILTERS ( Rating ) )
)

 

did not work on your real dataset

 

@MasonMA  code

 

VAR CurrentCount =
    DISTINCTCOUNT(StudentRatings[StudentID])

VAR TotalCount =
    CALCULATE(
        DISTINCTCOUNT(StudentRatings[StudentID]),
        REMOVEFILTERS(StudentRatings[Rating])
    )
RETURN
DIVIDE(CurrentCount, TotalCount, 0)

 

did work?

 

That would be weird as the codes are identical 🙂

 

Thanks for a clarification

 

Best

F

@FBergamaschi I am rather confused now because this morning when I used the code from MasonMA that I now see above it did not work and I got 100% all the way down the column:

VAR CurrentCount =
    DISTINCTCOUNT(StudentRatings[StudentID])

VAR TotalCount =
    CALCULATE(
        DISTINCTCOUNT(StudentRatings[StudentID]),
        REMOVEFILTERS(StudentRatings[Rating])
    )
RETURN
DIVIDE(CurrentCount, TotalCount, 0)

However, when I look at the email notification I received when MasonMA replied to my post, here is what his response said:

 

Screenshot 2025-07-23 091219.jpg

That code mentioned in the picture above is what worked, but I no longer see this post from MasonMA in this thread at all. 

 

So, in conclusion, here is what did work:

DIVIDE( DISTINCTCOUNT(StudentRatings[StudentID]), 
CALCULATE( DISTINCTCOUNT(StudentRatings[StudentID]), 
REMOVEFILTERS(StudentRatings[Rating]), ALLSELECTED() ) )   

As you mentioned specifically in messages that you have Slicers on report. ALLSELECTED () should be a more reliable solution because it preserves slicers, filters, and row context, and you only remove the Rating within the selected scope. I've updated the solution. Apology. 

 

 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.