Forum Discussion

Nicki's avatar
Nicki
Helper III
6 years ago
Solved

color formatting for Power BI Report

Hello, I want to have a unique color for each text field. I know I can create rules in Powe BI and assign color to each of them.  Then, I need to go to each chart or visual and assign color to the...
  • Anonymous's avatar
    Anonymous
    6 years ago

    HI Nicki,

    I'd like to suggest you do unpivot columns on your room fields to convert them to attribute and value, then add an index field to your table.

    After these steps, you can add a calculated column to the above table to get a random color based on DAX expressions and use on value field conditional formatting. (the rate to get duplicate color code is 1/256^3)

    RandomColor = 
    VAR cR =
        RANDBETWEEN ( [Index] - [Index], 255 )
    VAR cG =
        RANDBETWEEN ( [Index] - [Index], 255 )
    VAR cB =
        RANDBETWEEN ( [Index] - [Index], 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], "" )
    


    Regards,

    Xiaoxin Sheng