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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
dange187
Frequent Visitor

Dynamic Percentage of Parent Switch Order

Hi all,

I am trying to do a percentage of parent calculation which is fine but I am using field parameters so users can dynamically change the row selections in a matrix. If the rows are selected in a specific order then the calculation works fine but if they are selected out of order with the switch calculation then the wrong result is returned. I created a dummy table to represent my issue where there are 3 categories, brand, group and country.

DAX formula is:

"%Share =
VAR _brand = CALCULATE([SUMVALUE],ALLSELECTED('Table'[Brand]))
VAR _country = CALCULATE([SUMVALUE],ALLSELECTED('Table'[Country]))
VAR _group = CALCULATE([SUMVALUE],ALLSELECTED('Table'[Group]))
RETURN
SWITCH(TRUE(),
ISINSCOPE('Table'[Brand]),DIVIDE([SUMVALUE],_brand),
ISINSCOPE('Table'[Group]),DIVIDE([SUMVALUE],_group),
ISINSCOPE('Table'[Country]),DIVIDE([SUMVALUE],_country),
DIVIDE([SUMVALUE],CALCULATE([SUMVALUE],ALLSELECTED('Table')))
)"
If I select country as first level in matrix then group as second level, it works correctly for both levels of the matrix.
dange187_0-1697712922097.png

 

If I select group then country the second level is wrong. Presumably the group VAR is passing as true first giving sum of all groups in the selected country.
dange187_1-1697713046954.png

So my question is, how can I get it to select the correct VAR regardless of the order the field parameters are selected?

 

Dummy table I created here:

BrandGroupCountryValue
Brand1Group1GB37
Brand2Group1GB16
Brand3Group2GB16
Brand4Group2GB21
Brand5Group2GB21
Brand6Group3GB47
Brand7Group3GB41
Brand8Group3GB24
Brand9Group3GB25
Brand1Group1FR21
Brand2Group1FR49
Brand3Group2FR41
Brand4Group2FR22
Brand5Group2FR19
Brand6Group3FR37
Brand7Group3FR27
Brand8Group3FR16
Brand9Group3FR37
Brand1Group1DE9
Brand2Group1DE31
Brand3Group2DE17
Brand4Group2DE21
Brand5Group2DE50
Brand6Group3DE49
Brand7Group3DE33
Brand8Group3DE34
Brand9Group3DE40
 
6 REPLIES 6
RamanaiahM
Frequent Visitor

**bleep**! I have encountered the same scenario. when i found this post , i hurriedly scrolled down thinking some good soul would have already provided solution 😀

My post for help: Same problem as the one in this post, but more complicated. 

https://community.fabric.microsoft.com/t5/forums/recentpostspage/post-type/message/category-id/power...

 

Well, times have changed. Not a problem any more with Visual Calculations

 

lbendlin_0-1730839334388.png

 

lbendlin
Super User
Super User

Fascinating issue.  Your problem is that the SWITCH() statement exits once it finds a match, and you have to hard code the order it checks in.

 

In this scenario [Group] loses out because it comes last.

lbendlin_0-1697921232555.png

if you put it up front then it works again

lbendlin_1-1697921295954.png

 

I am not aware of a way to sense the order in which the field parameters have been selected by the user.  It can be shown visually through the Parameter table but -to my knowledge - not probed programmatically.

lbendlin_2-1697921408490.png

 

So you would need to overcome two large hurdles - first, know the order in which parameters were selected, and then, modify the switch statement dynamically.

 

Power BI Desktop and Service are missing the EVALUATE function, sadly.

 

EDIT:  This might be helpful: Using SELECTEDVALUE with Fields Parameters in Power BI - SQLBI

EDIT 2:  No, it's not.  It only provides which fields are selected but not the order they were selected in.

Thank you for your effort in looking into this. I think the problem requires too much effort to solve for the benefit. I've reverted to a simpler version that does not give a sum to 100% of the sub-category but always to 100% of the overall total.

I don't think you should mark my post as the solution (as there isn't currently one).  I'll see if I can come up with a workaround of sorts. The problem is also that you can add field parameters multiple times to a visual.  That would then make the "order of picking"  even more ambiguous.  Fun stuff!

Alberto confirmed that this is not currently possible.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.