Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi All,
I have matrix visual with 4 levels data in form of heirarchy , if we select level 1 values in matrix i want show level 2 values in Line chart , if we select level 2 in matrix visual, in lin chart i want to show level 3 data and so on.
i want to show dynamic levels in line chart legend.
| Level 1 | Level 2 | Level 3 | Level 4 | Sum of Amount | FY |
| A | Level1.1 | Level2.1 | Level3.1 | -458970 | FY22 |
| A | Level1.1 | Level2.1 | Level3.2 | -458970 | FY22 |
| A | Level1.1 | Level2.2 | Level3.3 | -458970 | FY22 |
| A | Level1.1 | Level2.2 | Level3.4 | -458970 | FY22 |
| A | Level1.1 | Level2.3 | Level3.5 | -458970 | FY22 |
| A | Level1.1 | Level2.3 | Level3.6 | -458970 | FY22 |
| B | Level1.2 | Level2.4 | Level3.7 | -458970 | FY22 |
| B | Level1.2 | Level2.4 | Level3.8 | -458970 | FY22 |
| B | Level1.2 | Level2.5 | Level3.9 | -458970 | FY22 |
| B | Level1.2 | Level2.5 | Level3.10 | -458970 | FY22 |
| B | Level1.2 | Level2.6 | Level3.11 | -458970 | FY22 |
| B | Level1.2 | Level2.6 | Level3.12 | -458970 | FY22 |
| C | Level1.3 | Level2.7 | Level3.13 | -458970 | FY22 |
| C | Level1.3 | Level2.7 | Level3.14 | -458970 | FY22 |
| C | Level1.3 | Level2.8 | Level3.15 | -458970 | FY22 |
| C | Level1.3 | Level2.8 | Level3.16 | -458970 | FY22 |
| C | Level1.3 | Level2.9 | Level3.17 | -458970 | FY22 |
| C | Level1.3 | Level2.9 | Level3.18 | -458970 | FY22 |
Hi @Ravi_G
Power BI doesn’t let you directly switch the legend column based on a slicer, which makes dynamic legends tricky. But there’s a workaround that’s worked well for me.
What I usually do is create a separate slicer table (not related to the model) that just holds the level names like “Level 1”, “Level 2”, “Level 3”. Based on what’s selected there, you can build a calculated column or measure that switches between the actual columns in your hierarchy.
Legend Label =
SWITCH(
SELECTEDVALUE(LevelSelector[Level]),
"Level 1", Table[Level2],
"Level 2", Table[Level3],
"Level 3", Table[Level4]
)
Then you use this Legend Label as the legend in your chart. It’s not truly dynamic in the sense of changing the metadata of the chart, but it gets the job done visually.
Just be aware that this works best when your hierarchy is flattened (i.e. columns for each level). If you're using a parent-child hierarchy, it’ll need a slightly different setup.
Hi @Ravi_G ,
Hi there, just following up on your query about Dynamic Legends based hierarchy selection. @rohit1991 has provided a response that may address your concern.
If his solution worked for you, please consider marking it as the Accepted Answer — this helps others in the community who might have the same question.
If you're still experiencing issues or need further clarification, feel free to add more details — we’re here to help!
Thanks again for being part of the Microsoft Fabric Community!
Hey there!
Here’s how you can achieve that using DAX measures and potentially slicers or selection controls in Power BI:
Create a Dynamic Measure for Line Chart: You'll need a dynamic DAX measure that changes its behavior based on the selected level from the matrix. For example, you can use a measure like this:
DynamicLevelMeasure =
SWITCH(
TRUE(),
SELECTEDVALUE('Hierarchy'[Level]) = 1, SUM('Data'[Level1Amount]),
SELECTEDVALUE('Hierarchy'[Level]) = 2, SUM('Data'[Level2Amount]),
SELECTEDVALUE('Hierarchy'[Level]) = 3, SUM('Data'[Level3Amount]),
SELECTEDVALUE('Hierarchy'[Level]) = 4, SUM('Data'[Level4Amount])
)
You can add a slicer or matrix to allow users to select which level they want to display. The slicer will control which level the line chart visual shows.
Create a line chart and add the DynamicLevelMeasure as the value.
For the x-axis, you can use a time-based or sequential field (e.g., a date or period column).
Ensure that the slicer (or matrix) that controls the level is properly interacting with the line chart. You can adjust the interactions via the Format pane in Power BI to control how selections in the matrix or slicer affect the line chart.
Hope this helps!
😁😁
Thank you for the reply ..i want claculated column that i need to place in Legend of line chart. and how we are assigning 1 to level SELECTEDVALUE('Hierarchy'[Level]) = 1 in above measure using parameters?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 36 | |
| 34 | |
| 31 | |
| 27 |
| User | Count |
|---|---|
| 136 | |
| 103 | |
| 66 | |
| 65 | |
| 56 |