Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Q&A with Qlik - Qlik Cloud Migration: Questions about migrating to Qlik Cloud? Catch the latest replay!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Help with setting bar chart color based on year

We have a bar chart that we always want to display 3 years no matter what. If the user picks 2016, we want to show 2016, 2015, and 2014. We also want to have the colors defined. Everything works when either no year is selected, or if 3 years are selected. So if the user picks no year, we see 2016, 2015, and 2014 and the colors we want. If they pick 2016,2015, and 2014 we see all 3 years and the colors we want.

The problem is when the user only picks one year, say 2016. We still see all 3 years, but the colors stop working.

Here is the formula for the always 3 years on the chart:

=Sum({<Year = {$(=Max(Year)), $(=Max(Year) - 1), $(=Max(Year) - 2)}>} AdmBrokrCommBaseAmt)/1000 

Here is the formula for the colors. We are using this in the background color expression:

Pick(Match(Year,$(vMaxSelectedYr),($(vMaxSelectedYr)-1),($(vMaxSelectedYr)-2)),RGB(201,187,23),RGB(45,64,199),RGB(34,235,2)) 

If someone could either provide us with a solution, or help us understand why it doesn't work when only 1 year is selected, that would be great. thanks!

Labels (1)
13 Replies
Not applicable
Author

This works, but only for current year of 2016. 2015 and 2014 are still 1 solid color.

=Pick(Match(Only({<Year>} Year), $(vMaxSelectedYr), ($(vMaxSelectedYr)-1), ($(vMaxSelectedYr)-2)),
(
if(Market = 'Secondary', RGB(201,187,23), blue())),
(
if(Market = 'Secondary', RGB(45,64,199), cyan())),
(
if(Market = 'Secondary', RGB(34,235,2),If(Market = 'New Issue',RGB(100,200,210),Green()))))

sunny_talwar
MVP
MVP

Try this:

=Pick(Match(Only({<Year>} Year), $(vMaxSelectedYr), ($(vMaxSelectedYr)-1), ($(vMaxSelectedYr)-2)),

(If(Only({<Year>} Market) = 'Secondary', RGB(201,187,23), blue())),

(If(Only({<Year>} Market) = 'Secondary', RGB(45,64,199), cyan())),

(If(Only({<Year>} Market) = 'Secondary', RGB(34,235,2), If(Only({<Year>} Market) = 'New Issue',RGB(100,200,210),Green()))))

Not applicable
Author

Works like a charm, thanks Sunny!

sunny_talwar
MVP
MVP

Awesome