Forum Discussion

XY_Z's avatar
XY_Z
Regular Visitor
18 days ago

Update matrix title background based on matrix row selection

Hi everyone,

I would like to make the title background color dynamic based on the values I select in the matrix. For example if I select row A, the color is white and if I select row B the color is black. The selection must be made to the matrix itself and not other visuals. 

Thank you,

4 Replies

  • Hi XY_Z​ 

    A visual cannot natively be filtered by selections made within that same visual. This means that any measure used for conditional formatting within that visual cannot natively depend on selections made within that same visual.

    However, a workaround is possible using the Preselected Slicer custom visual, whose selections can be controlled by a measure, and then in turn filter the original visual.

    Attached is a sample PBIX showing one way of setting it up:

    1. Three disconnected tables:
      1. Data: Sample fact table
      2. Colour: Contains possible title background colours, with Colour[Colour Hex] being the background colour code.
      3. Dummy: Table containing a single column with values true/false, required by Preselected Slicer.
    2. Create table visual where each row corresponds to a colour.
    3. Create measures shown below.
    4. Create Preselected Slicer visual with::
      1. Fields = Colour[Colour]
      2. Pre Selection = [Colour Flag]
      3. Dirty Status = Dummy[Dummy]
    5. Obscure Preselected Slicer visual (but don't hide it)
    6. Set the Table visual's title background colour to Field Value = Title Background Colour.
    7. Optional: Set the Table visual's title text colour to Field Value = Title Text Colour.
    8. Now selections made on the Table visual update the Preselected Slicer visual's selection.

     

    Colour Flag = SELECTEDVALUE ( Colour[Colour] ) = SELECTEDVALUE ( Data[Colour] )
    Title Background Colour = SELECTEDVALUE ( Colour[Colour Hex] ) 
    Title Text Colour = SELECTEDVALUE ( Colour[Text Colour Hex] )

    Another method is to create a separate shape positioned over the Table visual's title area, whose fill colour is set based on an appropriate measure.

  • ShahRukhSameer's avatar
    ShahRukhSameer
    Responsive Resident

    Hi XY_Z​,

    Yes, this is possible, but there’s a small catch: the matrix selection itself needs to drive a measure, and that measure can then be used for conditional formatting.

    For example, if your matrix uses Category[Category]:

    Title Background =
    SWITCH(
    SELECTEDVALUE(Category[Category]),
    "A", "#FFFFFF",
    "B", "#000000",
    "#FFFFFF"
    )

    You can then use this measure for the title/background conditional formatting if that formatting property supports fx.

    If you're referring specifically to the matrix's built-in title background, Power BI has some limitations around applying a measure directly to that property. In that case, a common workaround is to place a small shape/text box over the matrix and use conditional formatting on that instead.

    The important part is that clicking a row in the matrix creates the filter context, so you don't need a separate slicer or visual to make the selection.

  • v-saisrao-msft's avatar
    v-saisrao-msft
    Community Support

    HI XY_Z​,

    Checking in to see if your issue has been resolved. let us know if you still need any assistance.

    Thank you.