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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
201TinyTim
New Member

How to Calculate %Proportion of Hierarchy in Matrix

I have a matrix in the style of the below  with a heirarchy of country->product  and measures of "Special" products being for example only products A and B. (currently just a binary flag against products of if special or not and then seperate calculate for that to get Special only column)

 

Currently it is doing Proportion % per row   (i.e each row uses the underlined value as the denominator and the italics as the numerator) and i have tried multiple ways to make be Proportion of the Hierarchy tier   so it shows the product value proportion % compared to the  country total.  (Each Italics numerator is compared to the same single underlined denominator per country)


Current Version

HierarchySum All ProductsSum Special Only

Proportion% of Special in All

CountryA100025025%
->ProductA100100100%
->ProductB150150100%
->ProductC750  
CountryB etc2502510%
Total125027522%

 

Desired Version

HierarchySum All ProductsSum Special OnlyProportion% of Special in All
CountryA100025025%
->ProductA10010010%
->ProductB15015015%
->ProductC750  
CountryB etc2502510%
Total125027522%

 

Any and all help would be greatly appreciated

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @201TinyTim ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1706074547988.png

Measure = var _step1 = ADDCOLUMNS('Table',"sum",SUMX(FILTER(ALL('Table'),[Country]=EARLIER([Country])),[Sum All Products]))
var _step2 = ADDCOLUMNS(_step1,"Divide",DIVIDE([Sum Special],[sum]))
RETURN SUMX(_step2,[Divide])

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @201TinyTim ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1706074547988.png

Measure = var _step1 = ADDCOLUMNS('Table',"sum",SUMX(FILTER(ALL('Table'),[Country]=EARLIER([Country])),[Sum All Products]))
var _step2 = ADDCOLUMNS(_step1,"Divide",DIVIDE([Sum Special],[sum]))
RETURN SUMX(_step2,[Divide])

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Gayatri_D05
Resolver II
Resolver II

Hi @201TinyTim ,
I am not sure are calculating the %Proportion for Special or all products.
Any of them just use the following measure 

% = CALCULATE(SUM(All_products)/CALCULATE(SUM(All_products),ALL(Products)))

If you want to calculate for special just replace the all products wiht your special column.
also note that you would want to pass the product a, product b column in All() in order to get the deseried value.
Let me know if this works for you.

I hope I was able to resolve your issues. If yes do give it a like. 😊


 

 

 

Sadly this doesn't work.  I have editted the original request to try help show the %proportion logic better

Hi, Thanks for the detailed logic, can you please try this 

% = CALCULATE(SUM(Special_only)/CALCULATE(SUM(All_products),ALL(Products
)))

I tried it on my sample data it seems to work on it. Let me know if you are facing any issue.😊

It Generates the correct % on the Country row  but when expand the hierarchy down to view the product breakdown then those rows are still vastly off in %   even for the case where the country only has Product A and Product C (so just 1 Special product) and would expect the % to be the exact same as the country total calc which is correct of 10% it ends up showing 95% for the breakdown for A

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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