Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Vizard
Frequent Visitor

Measure formula not working to assign bar color

I created the following measure to assign colors to bars in a bar chart:

COLOR =
IF(SUM(CASES_COVID_VARIANTS[index]) = 3, "#8B4186",
IF(SUM(CASES_COVID_VARIANTS[index]) = 4, "#be5150",
IF(SUM(CASES_COVID_VARIANTS[index]) = 5, "f26724",
IF(SUM(CASES_COVID_VARIANTS[index]) = 6, "#faa21b",
IF(SUM(CASES_COVID_VARIANTS[index]) = 7, "#80af5a",
IF(SUM(CASES_COVID_VARIANTS[index]) = 8, "#1e988a",
IF(SUM(CASES_COVID_VARIANTS[index]) = 9, "#0070b9",
IF(SUM(CASES_COVID_VARIANTS[index]) = 10, "#132048",
IF(SUM(CASES_COVID_VARIANTS[index]) = 11, "#c5a0c3",
IF(SUM(CASES_COVID_VARIANTS[index]) = 12, "#d79392",
IF(SUM(CASES_COVID_VARIANTS[index]) = 1, "#A2A7A9",
"#FFFFFF")))))))))))
 
However, the colors are not being applied correctly. For example, the color assigned to index 10 shows up on index 1. Everything else comes out white. What's going on here? Do I need leading zeroes on my indices since there are more than 9?

Here's what my bar chart comes out looking like:
Screenshot 2025-06-20 094214.png
Any ideas on how to get this formula to work?

Thanks!
1 ACCEPTED SOLUTION
Cookistador
Super User
Super User

Hi @Vizard 

 

The issue can come from the sum of your dimension index, instead of using sum, can you try the following dax code:

 

COLOR = SWITCH( SELECTEDVALUE(CASES_COVID_VARIANTS[index]),

1, "#A2A7A9",

3, "#8B4186",

4, "#be5150",

5, "#f26724",

6, "#faa21b",

7, "#80af5a",

8, "#1e988a",

9, "#0070b9",

10, "#132048",

11, "#c5a0c3",

12, "#d79392",

"#FFFFFF" )

View solution in original post

1 REPLY 1
Cookistador
Super User
Super User

Hi @Vizard 

 

The issue can come from the sum of your dimension index, instead of using sum, can you try the following dax code:

 

COLOR = SWITCH( SELECTEDVALUE(CASES_COVID_VARIANTS[index]),

1, "#A2A7A9",

3, "#8B4186",

4, "#be5150",

5, "#f26724",

6, "#faa21b",

7, "#80af5a",

8, "#1e988a",

9, "#0070b9",

10, "#132048",

11, "#c5a0c3",

12, "#d79392",

"#FFFFFF" )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.