17 Replies Latest reply: Jun 13, 2018 12:14 PM by Semir Shewayish

# Dimension colours in stacked bar charts Qlik Sense

Hello

I have a bar chart that measures sales across a number of financial periods. For each period I want the bar to be broken down by customer category (i.e. stacked bar chart). So the bar chart has two dimensions, Period and Category. On the sheet, the period is a filter. The user can select a period and other objects on the sheet reflect various values for that period. But within the bar chart I want all periods to be shown and so I have the measure expression set as

sum({\$<Period=>}SalesValue)

When no period is selected each bar is shown as a stacked bar chart reflecting the various categories,

However, when a period is selected, only the selected period shows the categories,

Is it possible to make all periods show the categories when a period is selected?

Periods are 4 digits, first 2 are the year, last 2 represent the period in the year. E.g. 1710 means period 10 of year 17.

Categories are text, e.g. 'Shops'. There are 6 categories.

Thanks, appreciate any help that anyone can give.

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Hi Semir

Not sure what you are trying to achieve with the request.

If the user selects a period why is it an issue that only the users selection is coloured so they focus on their selection?

Regards

Andy

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Suppose you have rolling 12 months for example; and when u select a month; you want to show it and its previous 11 months.. but when u color with dimension; and select any month;; you'll have all the previous shown month scolored in grey..

So, we NEED to figure out a way to keep all the months colored and break the association

Do u see the point?

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

stalwar1, have any idea on how to do this?

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Are you using an expression for colors in the chart? If you are, then you might need to ignore selection in your color expression also... For example if the expression is like this

Color

change it to this

Only({1} Color)

or

Only({<Period>} Color)

Basically ignore selection in Period for your color expression also...

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

But I want to have different colors;

sthing like; if(dim='Value1',Green(),red())

how can I do in this case?

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Ignore selection for dim field

If(Only({<Period>} dim) = 'Value1', Green(), Red())

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

That's it !

semgem12 , try to replicate such a thing in ur applicaion

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Yes that works, thank you very much! Thanks to Omar too.

In case this helps anyone I created an inline table to describe the RGB colours for each type of category,

Category,CategoryRed,CategoryGreen,CategoryBlue

Shops,180,190,250

Restaurants,200,210,250

Supermarkets,220,230,250

];

Then in the bar chart properties, appearance, colours and legend, I set Colours to Custom and By expression. The expression is

rgb(only({<Period>}CategoryRed),  only({<Period>}CategoryGreen),  only({<Period>}CategoryBlue))

Make sure to tick 'The expression is a color code'

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Hi,

I have the same problem here and used the technique you gave and it worked. But the Legend is getting disappeared. Can you please help with this?

Thank you.

Regards

Santhosh Kasam

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Can you include an image of the problem?

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Hi Semir,

If you observer it does not indicate which color belongs to which bucket. That is the LEGEND is Missing. Please help.

Thank you

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Hi Santosh

Just looked back at the Qlik Sense app where I used this approach. I'm afraid I wasn't able to include a legend within the chart. I was lucky in that I had only 3 categories and so created 3 KPIs that only showed text .... on the KPI I set the Data to be the required text, e.g. 'Shops' and then on the appearance tab switched off conditional colours and then set the colour to the required colour for that category. I used KPI because it gave more flexibility in colour choice rather than a text box.

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

Hi Semir,

This can be done in a different way too. I just found today. Create a master dimension and define the colors for each value in it. Then add the dimension to the chart. Mark the colors and Legend to Auto mode. Then everything works perfectly.

I think it's worth trying. Thank you.

Regards

Santhosh Kasam

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

That's great, thanks Santhosh I'll give it a try.

• ###### Re: Dimension colours in stacked bar charts Qlik Sense

So is the issue down to how the setting of colour is being applied to the chart using colour by Expression rather than using the colour by dimension and measure features added in master items?

Ive not come across the issue myself but perhaps tackling the adding of colour in a different way will resolve this.

Regards

Andy