Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Using If to change background colour of bar chart

I have the following expression applied to the background of a bar chart -

If(Year='Target 2014-15', lightred(), color(1))

It changes the colour of the bar to red for my 2014-15 target.  I want it to do the same when Year = 'Target 2015-16' and 'Target 2016-17'. Essentially I want the targets to appear a different colour to the actual historic Year values.

How do I write the code to do this?

Thanks

Greg

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

If(Year='Target 2014-15', lightred(), If(Year='Target 2015-16', green(), color(1)))

or

If(Year='Target 2014-15' or Year = 'Target 2015-16', lightred(), color(1)))


View solution in original post

5 Replies
MK_QSL
MVP
MVP

If(Year='Target 2014-15', lightred(), If(Year='Target 2015-16', green(), color(1)))

or

If(Year='Target 2014-15' or Year = 'Target 2015-16', lightred(), color(1)))


Anonymous
Not applicable
Author

if you want red for all 3 targets

if (year='Target 2016-15' and year='Target 2015-16' and year='Target 2016-17', lightred(), Color(1))

if you wsnt other colours

if (year='Target 2016-15', lightred, if year='Target 2015-16, lightgreen, if (ýear....

thats what you want?

Anonymous
Not applicable
Author

Thanks Manish and Rudolf.  It is working now thanks to your solutions.  I wonder also if there is a way to do this when Year starts with 'Target...'.  That way I can future proof the code for when future targets are added.

Anonymous
Not applicable
Author

in my solution it should be "or" instead of "and". sorry.

to your question: you can use

if (left(year,6)='Target', lightred

Anonymous
Not applicable
Author

Excellent!  Thanks Rudolf.

Greg