Forum Discussion
Custom Subtotals in Matrix for Different Categories
- 7 years ago
So if you unpivot and use the disconnected table it should work fine.
Note: I would hide the variable column in Table1 as the switch measure is based off the 'Variable' table. If you use the column from Table1 the measure will not work.
atpbi10 wrote:
Hey thanks for this hint. It works nicely for one level matrix. How about if we have two level nested matrix? Like there are multiple variables for each of top level and I want to have custom subtotals for the top level variables but still be able to drill down and see the correspodning subvariables one level below.
I tried this solution but there are some weird things happening with the matrix table.
It's hard to say as you have not provided any detail and I can't help fix "weird things" without details of what is going on. In theory you should be able to make this technique work across multiple levels, but it may get complicated an you may need to have multiple levels of nested switch statements.
Can you provide a link to an example pbix file with some data the shows what you are trying to do? If you can also provide the expected out comes given the example data and how you want the calculations to work we can probably help you out. (see https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490 )
So here is my example file. I have three levels in the matrix table. As you can see in my attempt using your solution it changes all the values for the given variable that I want to have custom total. Instead of whats happening my desired result would be to only apply the custom total on the highest level (level 1-which is "Variable" column). And if I drill down then the values would behave normally, so they would sum for the corresponding variable in the input file.
https://drive.google.com/file/d/1wC78oj6i9srmW7B0U2bUEIR7KqlNSV2N/view?usp=sharing
- d_gosbell4 years ago
Super User
As I suggested earlier you can do this by adding some nested logic. So inside the "Gross Profit" condition we can then check if there are any filters on the L2 or L3 tables (if they are not filtered then we are looking at a total value).
eg.
Measure = SWITCH ( SELECTEDVALUE ( 'Sheet1'[Variable] ), "Gross profit", SWITCH ( TRUE (), NOT ( ISFILTERED ( VariableL2 ) || ISFILTERED ( VariableL3 ) ), 12, SUM ( 'Sheet1'[Value] ) ), SUM ( Sheet1[Value] ) )This produces the following output