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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
korina
Helper I
Helper I

Calculating percentage of subtotals with dynamic filtering

Hello,

 

I am trying to create a line chart like the one below, calculating the percentage of each gender within each category, rather than that of the total population:

Capture3.PNG

I have used two formulas to achieve that.

 

First, I created a new column:

Total by Category = CALCULATE(COUNT(Headcount[Pers. No.]), ALLEXCEPT(Headcount, Headcount[Categories]))
 
And then, based on that, a measure:
Employees% = Headcount[Employees] / MAX(Headcount[Total by Category])
 
The problem starts when I use one of the filters at the top of the page (Division, Subdivision, Org. Unit).
I try to work around this by including them in the "Total by Category" calculation, like this:
Total by Category = CALCULATE(COUNT(Headcount[Pers. No.]), ALLEXCEPT(Headcount, Headcount[Categories], Headcount[Division], Headcount[Subdivision], Headcount[Org. Unit]))
 
However, this fixes the problem for the deepest level (Org. Unit), and when I filter by subdivision I get really weird percentages (the sums of the org. units of that subdivision).
 
Can anyone help me fix this?
 
Thank you very much,
Korina
1 ACCEPTED SOLUTION

Hello @Anonymous! Thank you for your help.

 

Unfortunately, DAX syntax doesn't allow for more than 2 arguments to be passed to the Filter function, so it doesn't work.

 

However, I posted this problem again, and somebody found a solution, please see below:

 

https://community.powerbi.com/t5/Desktop/100-Stacked-Line-Chart-responding-to-slicers-filters/m-p/1521064

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@korina 

 

You would need to use Allselected instead of ALLEXCEPT. Try the following measure:

Total by Category = CALCULATE(COUNT(Headcount[Pers. No.]), Filter(Allselected(Headcount),[Categories]=MAX([Categories]), [Division]=MAX([Division]), [Subdivision]=MAX([Subdivision]), [Org. Unit]=MAX([Org. Unit])))


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Hello @Anonymous! Thank you for your help.

 

Unfortunately, DAX syntax doesn't allow for more than 2 arguments to be passed to the Filter function, so it doesn't work.

 

However, I posted this problem again, and somebody found a solution, please see below:

 

https://community.powerbi.com/t5/Desktop/100-Stacked-Line-Chart-responding-to-slicers-filters/m-p/1521064

 

 

amitchandak
Super User
Super User

@korina , Try a measure like this and check 

Total by Category = CALCULATE(COUNT(Headcount[Pers. No.]), Filter(allselected(Headcount), Headcount[Categories] = all(Headcount[Categories])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you @amitchandak 

 

I have tried this, and I get the following error:

Capture4.PNG

Any ideas?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.