Forum Discussion

HPS1RT's avatar
HPS1RT
Frequent Visitor
2 years ago
Solved

Power BI table colour coding based on other visual

Hello Community,

I have column chart and table in one report page. Is there a possibilty to display the colour coding in the table based on colour of that text value in other visual?


Thank you in advance:)

  • Hi HPS1RT 

     

    Yes , it is possible. If you want to have control over specific colors over bars you can add new dimension to your table that will map category with color. 

     

    Then you can use conditional formatting in Matrix/Table or Column Char that will format colors based on Field Value based on Column including Hexidecimal/Color name.

     

    See the example below:

     

     

     

     

    Hope it helps!

  • Hi HPS1RT 
    You can create Dax with color coding and use a created measure for all the visuals. 
    For example :

    color = SWITCH(SELECTEDVALUE('Table'[category]),
    "a","red",
    "b","blue",
    "c", "#3f007d")

    or for graph :

    pbix is attached

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Hi HPS1RT 
    No, this can work only with Dax we don't have the functionality of coloring visuals based on other visuals, so you have to have some logic to get the colors.

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

     

7 Replies

  • Hi HPS1RT 

     

    You can add new calculated column to your dim (categories) and use this syntax:

     

    RandomColor = 
    VAR cR =
        RANDBETWEEN (0, 255 )
    VAR cG =
        RANDBETWEEN (0, 255 )
    VAR cB =
        RANDBETWEEN ( 0, 255 )
    VAR RedP0 =
        MOD ( cR, 16 )
    VAR RedP1 =
        MOD ( INT ( cR / 16 ), 16 )
    VAR GreenP0 =
        MOD ( cG, 16 )
    VAR GreenP1 =
        MOD ( INT ( cG / 16 ), 16 )
    VAR BlueP0 =
        MOD ( cB, 16 )
    VAR BlueP1 =
        MOD ( INT ( cB / 16 ), 16 )
    VAR hexTable =
        ADDCOLUMNS (
            { RedP1, RedP0, GreenP1, GreenP0, BlueP1, BlueP0 },
            "Hex", SWITCH (
                [Value],
                10, "A",
                11, "B",
                12, "C",
                13, "D",
                14, "E",
                15, "F",
                [Value]
            )
        )
    RETURN
        "#" & CONCATENATEX ( hexTable, [Hex], "" )

     

    Something similar was presented here:
    Solved: Create calculated column in DAX for random hex col... - Microsoft Fabric Community

     

    Hope it helps!

    • HPS1RT's avatar
      HPS1RT
      Frequent Visitor

      Hello StrategicSavvy 
      Thats wonderful. Thank you for your answer. 
      Actually if I use the stacked column chart, then I don't have option for conditional formatting. Any idea how to tackle this?

  • Hi HPS1RT 
    You can create Dax with color coding and use a created measure for all the visuals. 
    For example :

    color = SWITCH(SELECTEDVALUE('Table'[category]),
    "a","red",
    "b","blue",
    "c", "#3f007d")

    or for graph :

    pbix is attached

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Hi HPS1RT 

     

    Yes , it is possible. If you want to have control over specific colors over bars you can add new dimension to your table that will map category with color. 

     

    Then you can use conditional formatting in Matrix/Table or Column Char that will format colors based on Field Value based on Column including Hexidecimal/Color name.

     

    See the example below:

     

     

     

     

    Hope it helps!

    • HPS1RT's avatar
      HPS1RT
      Frequent Visitor

      Hello StrategicSavvy , Ritaf1983 
      Thank you for your reply.
      Sorry I forgot to mention. I have "n" number of categories and I cannot define the colors to each of it. 
      can we make it something more dynamic such that categories in the table takes the color based on category color in column chart?
      Thank you:)

      • Ritaf1983's avatar
        Ritaf1983
        Super User

        Hi HPS1RT 
        No, this can work only with Dax we don't have the functionality of coloring visuals based on other visuals, so you have to have some logic to get the colors.

        If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly