The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi,
How to create hierarchy for measures in matrix table?
As shown in the pic below, Net Sales is at top (has level 1 hierarchy) and 'Net Trade Sales' and 'Trade Sales' have a level 2 hierarchy
Solved! Go to Solution.
Hi @VanshikaB ,
I think you can try ISINSCOPE() function to update your measure.
In my sample:
Display Sales =
VAR _1 =
SWITCH (
TRUE (),
SELECTEDVALUE ( 'Hierarchy'[Level 2] ) = "Net Trade Sales", [Net Trade Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 2] ) = "Trade Sales", [Trade Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 1] ) = "Net Sales", [Net Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 1] ) = "Interco Sales", [Interco Sales],
BLANK ()
)
RETURN
IF (
ISINSCOPE ( 'Hierarchy'[Level 2] ),
IF ( MAX ( 'Hierarchy'[Level 2] ) = BLANK (), BLANK (), _1 ),
IF ( ISINSCOPE ( 'Hierarchy'[Level 1] ), _1 )
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @123abc,
Not getting the results as you mentioned
Below are the steps that I did, pls let me know if there is some mistake in the steps,
1) Created measures
2) Created Hierarcy table -
3) Created Switch Measure
4) Created Matrix
Also can drill down option be added to level1 Hierarchy?
Hi @VanshikaB,
I think 123abc's reply is helpful, however the code needs to be updated. If we add Level 1 = Net Sales firstly, all level 2 below it will return [Net Sales].
Display Sales =
SWITCH(
TRUE(),
SELECTEDVALUE('Hierarchy'[Level 2]) = "Net Trade Sales", [Net Trade Sales],
SELECTEDVALUE('Hierarchy'[Level 2]) = "Trade Sales", [Trade Sales],
SELECTEDVALUE('Hierarchy'[Level 1]) = "Net Sales", [Net Sales],
SELECTEDVALUE('Hierarchy'[Level 1]) = "Interco Sales", [Interco Sales],
BLANK()
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hey,
Got the required hierarchy format.
Although there is an issue - Interco Sales does not have a Level 3 hierarchy so it is giving blank after drill down, is there a way to remove the blanks?
This blank issue can appear whenever there are no further hierarchies
Hi @VanshikaB ,
I think you can try ISINSCOPE() function to update your measure.
In my sample:
Display Sales =
VAR _1 =
SWITCH (
TRUE (),
SELECTEDVALUE ( 'Hierarchy'[Level 2] ) = "Net Trade Sales", [Net Trade Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 2] ) = "Trade Sales", [Trade Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 1] ) = "Net Sales", [Net Sales],
SELECTEDVALUE ( 'Hierarchy'[Level 1] ) = "Interco Sales", [Interco Sales],
BLANK ()
)
RETURN
IF (
ISINSCOPE ( 'Hierarchy'[Level 2] ),
IF ( MAX ( 'Hierarchy'[Level 2] ) = BLANK (), BLANK (), _1 ),
IF ( ISINSCOPE ( 'Hierarchy'[Level 1] ), _1 )
)
Result is as below.
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Thanks its working
Hierarchy Table: Based on the file and images, you created a Hierarchy table with levels like Net Sales, Net Trade Sales, Trade Sales, etc. This is correct, but we need to ensure that this hierarchy is linked properly with the measures and matrix structure.
Switch Measure: Make sure the SWITCH function properly assigns values based on the hierarchy levels. Ensure the Hierarchy[Level] column values exactly match the strings in the SWITCH measure. Here’s an example of how it should look:
Display Sales =
SWITCH(
TRUE(),
SELECTEDVALUE(Hierarchy[Level]) = "Net Sales", [Net Sales],
SELECTEDVALUE(Hierarchy[Level]) = "Net Trade Sales", [Net Trade Sales],
SELECTEDVALUE(Hierarchy[Level]) = "Trade Sales", [Trade Sales],
SELECTEDVALUE(Hierarchy[Level]) = "Interco Sales", [Interco Sales],
BLANK()
)
Matrix Setup:
Since you want to mimic drill-down behavior, you’ll need to structure the data so that the hierarchy is multi-leveled, similar to how you would with fields. Here’s an approach to implement drill-down functionality:
Hierarchy Drill-Down in Power BI: You can modify your hierarchy table to include separate columns for each level of the hierarchy (e.g., Level 1, Level 2), and then place them in the matrix to enable drill-down:
Example Hierarchy Table:
Net Sales | Net Trade Sales |
Net Sales | Trade Sales |
Interco | Interco Sales |
This way, you can drag Level 1 and Level 2 into the rows of the matrix to enable drill-down.
Matrix Settings for Drill-Down: In the matrix visual, ensure that the drill-down option is enabled:
By separating the hierarchy into multiple columns, you’ll have the ability to expand and collapse different levels of the hierarchy, simulating a drill-down effect.
If you’re still not seeing the correct values, ensure that your Switch function matches the Level values exactly, including any possible spacing or capitalization issues.
Let me know if this resolves the issue, or if you need further adjustments!
Create Individual Measures: Create separate measures for each of the calculations (Net Sales, Net Trade Sales, Trade Sales, etc.).
Create a Switch Measure: Use a switch measure to control what should be displayed based on the selected hierarchy level.
Create a Hierarchy Table: You can manually create a small table that defines the hierarchy for your measures.
Example table for hierarchy:
LevelNet Sales |
Net Trade Sales |
Trade Sales |
Interco Sales |
Add the Hierarchy to the Matrix:
This approach will create a visual structure that mimics hierarchical measures in Power BI. Let me know if you need more clarification or assistance!