Forum Discussion
Change Bar Chart Legend based on isfiltered()
- 1 year ago
Your ISFILTERED approach won't work because a field parameter is basically a calculated table, and they are only calculated during data refresh, so they cannot take into account any slicers or filters.
If you revert the field parameter table to what it was originally, or create a new one, you can create a measure like
Selected Legend Level = VAR VisibleProjectTypes = COUNTROWS ( VALUES ( 'Table'[Project Type] ) ) VAR CurrentLegendLevel = SELECTEDVALUE ( 'Legend Level'[Legend Level Order] ) VAR Result = IF ( VisibleProjectTypes = 1 && CurrentLegendLevel = 0, 1, 0 ) RETURN Resultwhich will return 1 if there is only 1 project type selected and the appropriate legend level is in the filter context.
On your bar chart use the field parameter as the legend and add a TopN filter to only show the top 1 rows, using the new measure as the value. It will automatically change the legend level based on the user interactions.
Your ISFILTERED approach won't work because a field parameter is basically a calculated table, and they are only calculated during data refresh, so they cannot take into account any slicers or filters.
If you revert the field parameter table to what it was originally, or create a new one, you can create a measure like
Selected Legend Level =
VAR VisibleProjectTypes =
COUNTROWS ( VALUES ( 'Table'[Project Type] ) )
VAR CurrentLegendLevel =
SELECTEDVALUE ( 'Legend Level'[Legend Level Order] )
VAR Result =
IF ( VisibleProjectTypes = 1 && CurrentLegendLevel = 0, 1, 0 )
RETURN
Result
which will return 1 if there is only 1 project type selected and the appropriate legend level is in the filter context.
On your bar chart use the field parameter as the legend and add a TopN filter to only show the top 1 rows, using the new measure as the value. It will automatically change the legend level based on the user interactions.
Unfortunately, that does not have any effect either. I like the idea though.
- johnt751 year ago
Super User
did you put the TopN filter on the field parameter ? what behaviour are you seeing ?
- Test_User_89341 year agoFrequent Visitor
I must correct myself. It works as intended when choosing Bottom 1 instead of Top 1. Thank You!