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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply

How to calculate percentage of column total?

2.png

 
Hi DAX gurus,

I have some good news! AI won't be replacing us anytime soon. Both ChatGPT and CoPilot were unable to solve this.

All I am trying to do is write a dynamic DAX measure that calculates the percentage of students who obtained a grade X over the column total. 

I have many filters/slicers on this page. As you can see in the attached image, the default tooltip for "100% stacked bar chart" gives the right percentage (15.38%, in this case) every time. I can change the filters that affects the total, and I still get the correct percentage.

My written DAX measure Grade Percentage fails to do so. I'd like your help in writing the correct DAX measure. I will eventually use this measure to create a customized Tooltip.

P.S. - The REPLY has the Data Model too.


Many thanks,
Sarthak


1 ACCEPTED SOLUTION
GeraldGEmerick
Responsive Resident
Responsive Resident

@sarthakgirdhar The classic approach to this would be something along the lines of:

% Total = 
VAR _Total = CALCULATE( COUNTROWS( 'Course Grades' ), ALLSELECTED( 'Course Grades' ) )
VAR _Part = COUNTROWS( 'Course Grades' ) 
// or something like COUNTROWS( FILTER( 'Course Grades', [Grade] = "A" )
VAR _Return = DIVIDE( _Part, _Total )
RETURN _Return

View solution in original post

5 REPLIES 5
v-priyankata
Community Support
Community Support

Hi @sarthakgirdhar 

Thank you for reaching out to the Microsoft Fabric Forum Community.

@GeraldGEmerick Thank you for your prompt response.

I'm glad your issue has been resolved. Please mark the helpful reply or your own response as the solution so it can assist others with similar issues.

GeraldGEmerick
Responsive Resident
Responsive Resident

@sarthakgirdhar The classic approach to this would be something along the lines of:

% Total = 
VAR _Total = CALCULATE( COUNTROWS( 'Course Grades' ), ALLSELECTED( 'Course Grades' ) )
VAR _Part = COUNTROWS( 'Course Grades' ) 
// or something like COUNTROWS( FILTER( 'Course Grades', [Grade] = "A" )
VAR _Return = DIVIDE( _Part, _Total )
RETURN _Return

Hey @GeraldGEmerick,

Thank you for your reply!

I figured out the issue. It wasn't my DAX measure that was the issue, it was actually the "100% stacked Bar chart".
You see, the aforementioned visual already normalizes the values, and with my measure, there was double normalization that was happening hence, the wrong percentage. The calculation works just fine on the "normal" Stacked bar chart.

Glad to hear it!

3.png

 

THE DATA MODEL

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.

August 2025 community update carousel

Fabric Community Update - August 2025

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