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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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 @V-pazhen-msft! 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/15...

 

 

View solution in original post

4 REPLIES 4
V-pazhen-msft
Community Support
Community Support

@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 @V-pazhen-msft! 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/15...

 

 

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])))

Thank you @amitchandak 

 

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

Capture4.PNG

Any ideas?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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