Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.
Hi everyone,
I'm working on a Power BI report using a line graph visual, and I'm using two tables:
Both tables are connected via the Area column.
My line chart is set up like this:
What I'm trying to achieve:
When I select an Area from the slicer (Table1), the line chart correctly shows all cities in that Area — which is what I want, so I can compare their performance over time.
But when I select a specific City from Table1, I want the line representing that city to automatically turn black in the graph, while all other cities from that area stay visible but in Regular colours . This would help visually highlight the selected city without removing the others from view.
Current workaround:
Right now, I’m manually going into the Format pane > Data colors and setting the selected city's color to black — but I’d like to automate this using a DAX measure and conditional formatting.
My goal:
Use a DAX measure that checks if the current city in the chart matches the selected city in the slicer and changes its color accordingly (black if selected, while still showing all cities from the selected Area.
Has anyone done something similar or found a reliable way to implement this? Would really appreciate any suggestions or workarounds!
Thanks so much!
Solved! Go to Solution.
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.
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.
Hi,
Share the download link of the PBI file.
User | Count |
---|---|
84 | |
73 | |
72 | |
56 | |
51 |
User | Count |
---|---|
43 | |
41 | |
36 | |
34 | |
30 |