Forum Discussion

manialla's avatar
manialla
Frequent Visitor
1 year ago
Solved

Dynamically Highlight Selected City in Line Graph Using DAX for Conditional Formatting

Hi everyone, I'm working on a Power BI report using a line graph visual, and I'm using two tables: Table1: Contains Area and City columns — used as slicers. Table2: Contains City, Area, Date, and...
  • danextian's avatar
    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.