7 Replies Latest reply on Jun 28, 2016 11:49 AM by Ryan Jablon

# one or a couple bars in a bar graph a different color based on a condition

How what I write a calculated field in order to get one or a group of bars in a bar graph to be a different color from the rest? I have like 2015 and 2016 data group together for various categories. I want the 2015 data to show up gray and the 2016 data to be the color it was randomly assigned based off the group it's apart of.

• ###### 1. Re: one or a couple bars in a bar graph a different color based on a condition

Hey Ryan,

Make a calculated field to determine the color and drag it to "color".

Something like this:

IF ATTR([Year]) = 2015 THEN 'grey'

ELSEIF ATTR([Year]) = 2016 AND SUM([Profit]) > 0 THEN 'green'

ELSEIF ATTR([Year]) = 2016 AND SUM([Profit]) <= 0 THEN 'red'

ELSE 'light grey'

END

• ###### 2. Re: one or a couple bars in a bar graph a different color based on a condition

Thank you for your reply Derrick. My Year measure however is written FY 2015 and contains 4 quarters so would it need to be like

IF INT([Year, Qtr of Date]) = 2015 THEN 'gray'

ELSE 'green'

END

The else being q1 and q2 of 2016**

• ###### 3. Re: one or a couple bars in a bar graph a different color based on a condition

*my dimension is written FY 2015 Q1, FY 2015 Q2, FY 2015 Q3, FY 2015 Q4, etc.

• ###### 4. Re: one or a couple bars in a bar graph a different color based on a condition

Sure; whatever it takes to get the year out of your particular dimension should work. You could do a combination of LEFT/RIGHT too if INT gives you any issues.

• ###### 5. Re: one or a couple bars in a bar graph a different color based on a condition

Not sure why it's not working, can it not identify FY 2015 Q1,2,3,4 etc. if I just say IF INT([Year, Qtr of Date]) = 2015. Should I do something like IF ([Year, Qtr of Date]) = 'FY 2015'?

• ###### 6. Re: one or a couple bars in a bar graph a different color based on a condition

You'd have to try it out to see what INT() typecasts "FY 2015 Q1" to, but my guess is something like 20151 instead of 2015.

If your string looks exactly like "FY 2015 Q1", then you should be able to do this to get the year: INT(RIGHT(LEFT([Year], 7), 4))

• ###### 7. Re: one or a couple bars in a bar graph a different color based on a condition

Okay thank you for your help.