Forum Discussion
Dynamically Highlight Selected City in Line Graph Using DAX for Conditional Formatting
- 1 year ago
Hi manialla
What you're trying to do requires conditional formatting on legends which currently isn't supported. There is a workaround which may work for a few number of items or more (if you have the patience to manually set the legend color). This requires using two disconnected tables to return the category value/legends.
Below is a sample measure that references two disconnected tables.
Value2 = VAR _value = CALCULATE ( [Sum of Value], TREATAS ( VALUES ( City02[City] ), 'Table'[City] ), TREATAS ( VALUES ( City01[Area] ), 'Table'[Area] ) ) VAR _value2 = CALCULATE ( [Sum of Value], TREATAS ( VALUES ( City02[City] ), 'Table'[City] ) ) VAR _areaCheck = ISFILTERED ( City01[Area] ) VAR _selected = IF ( SELECTEDVALUE ( City02[Category] ) = "selected", IF ( NOT _areaCheck, _value2, _value ) ) VAR _unselected = IF ( SELECTEDVALUE ( City02[Category] ) = "unselected", IF ( NOT _areaCheck, _value2, _value ) ) RETURN IF ( NOT ( HASONEVALUE ( City01[City] ) ) || NOT ( ISFILTERED ( City01[City] ) ), _unselected, IF ( SELECTEDVALUE ( City02[City] ) IN VALUES ( City01[City] ), _selected, _unselected ) )Please see the attached sample pbix.
Hello manialla
City Line Color =
VAR SelectedCity = SELECTEDVALUE('Table1'[City])
VAR CurrentCity = SELECTEDVALUE('Table2'[City])
RETURN
IF (
SelectedCity = CurrentCity,
"#000000", -- black
"#C0C0C0" -- gray or any default color
)
Create column chart and use above measure to CF
Then switch to Line chart
Thanks,
Pankaj Namekar | LinkedIn
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.