Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 them one by one.
For example, Floor 1 is blue in differnt chart , AAA1 of Room1 is in Floor 1 has alaways red color.
If I have 100 floors, 250 rooms and 100 visuals in my report, it is very hard to go one by one and change them.
Is there any way, that we create a file with color for each item and add it to the report,
and power bi can use that colors in order to assign them to text fields.
I do not mean themes(Json file) that we can add to have our own Color palettes
, but my request is different and I need it to assign color to text fields for all visuals that have that text field.
I apperciate any suggestion or response,
Thanks
Nicki
Solved! Go to Solution.
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
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
Thank you for response and share your file.
Your solution is good to create a color for each data point by DAX.
I can add a column to my table for color and assign color to each data point.
The only thing, conditional formatting applies to all bar and columns charts, Scatter chart, Treemap,
Funnel chart, Table, Matrix.
And there is no “select advanced controls” or “default color” for Pie, Donut, Line charts.
Then we can not use the color value column for these type charts.
If Microsoft can add a feature that we can add a Json file or any file for color in visuals, it will be great.
Nicki
Conditional formatting is by visual, not by column.
But - you can base the conditional formatting of any table cell on a text value in another column or measure that represents either the name of a color or the hex code. So if you really wanted to you could use isfiltered or isinscope to figure out which column you are on, and then set the colors accordingly.
Please think about the UX before you do any of this. Just because you can go crazy with colors doesn't mean you should.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
2 | |
2 | |
1 | |
1 |
User | Count |
---|---|
21 | |
2 | |
2 | |
2 | |
2 |