Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
riclight89
Contributor II
Contributor II

(issue) Colour Expression per Category on Multiple Month Bar Chart

Hi,

I have a bar chart which calculates the top x brands per month for the last 12 months. I am trying to give these brands a specific colour each using the colour expression:

riclight89_0-1672823958014.png

Sales Expression:

 

 

sum({$<CreateYear=, CreateMonth=, CreateYearMonth = {">$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),0),'YYYYMM'))"}>}Sales)

 

 

 Sales Colour Expression:

 

 

if(Category = 'A',RGB(255,0,0),
if(Category = 'B',RGB(0,76,153),	
if(Category = 'C',RGB(0,102,204),	
if(Category = 'D',RGB(220,20,60),
if(Category = 'E',RGB(0,0,255),	
if(Category = 'F',RGB(0,0,128),
if(Category = 'G',RGB(0,128,255),
if(Category = 'H',RGB(160,160,160),
if(Category = 'I',RGB(255,51,51),
if(Category = 'J',RGB(255,215,0),
if(Category = 'K',RGB(255,0,0),
if(Category = 'L',RGB(0,191,255),
if(Category = 'M',RGB(178,34,34),
if(Category = 'N',RGB(139,0,0),
if(Category = 'O',RGB(0,110,0),
if(Category = 'P',RGB(220,20,60)
,RGB(200,200,200)))))))))))))))))

 

 

 

result is only the last Bar receiving the colour allocations:

riclight89_1-1672824213737.png

I have tried using the colour expression in the dimension Category Colour expression as well. I'm guessing the multiple month aggregation has something to do with it, checking if there is a solution?

Thanks in advance,

Ric

Labels (1)
1 Solution

Accepted Solutions
QFabian
Specialist III
Specialist III

Hi @riclight89 , i tried to recreate your data and the chart, and i get this :

When there is a Month or Period selected, that period in chart is painted

QFabian_0-1672860485560.png

 

So, you need to put your set analysis expression in the color formula too.

{$<CreateYear=, CreateMonth=, CreateYearMonth = {">$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),0),'YYYYMM'))"}>}

 

 

This is my example, i tried to reduce the expression using variables :

vPeriod12 = =num(addmonths(date(CreateYearMonth, 'YYYYMM'), -12))

vPeriod1 = =max(CreateYearMonth)

QFabian_2-1672861253252.png

 

then using this chart expression  :

sum({<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>} Sales)

and seeing the chart like this, when one month and year is selectd :

QFabian_3-1672861300980.png

 

Color  expression :

ONLY(

{<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>}


if(Category = 'A',RGB(255,0,0),
if(Category = 'B',RGB(0,76,153),
if(Category = 'C',RGB(0,102,204),
if(Category = 'D',RGB(220,20,60),
if(Category = 'E',RGB(0,0,255),
if(Category = 'F',RGB(0,0,128),
if(Category = 'G',RGB(0,128,255),
if(Category = 'H',RGB(160,160,160),
if(Category = 'I',RGB(255,51,51),
if(Category = 'J',RGB(255,215,0),
if(Category = 'K',RGB(255,0,0),
if(Category = 'L',RGB(0,191,255),
if(Category = 'M',RGB(178,34,34),
if(Category = 'N',RGB(139,0,0),
if(Category = 'O',RGB(0,110,0),
if(Category = 'P',RGB(220,20,60)
,RGB(200,200,200)))))))))))))))))
)

 

 

QFabian

View solution in original post

4 Replies
QFabian
Specialist III
Specialist III

Hi @riclight89 , i tried to recreate your data and the chart, and i get this :

When there is a Month or Period selected, that period in chart is painted

QFabian_0-1672860485560.png

 

So, you need to put your set analysis expression in the color formula too.

{$<CreateYear=, CreateMonth=, CreateYearMonth = {">$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),0),'YYYYMM'))"}>}

 

 

This is my example, i tried to reduce the expression using variables :

vPeriod12 = =num(addmonths(date(CreateYearMonth, 'YYYYMM'), -12))

vPeriod1 = =max(CreateYearMonth)

QFabian_2-1672861253252.png

 

then using this chart expression  :

sum({<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>} Sales)

and seeing the chart like this, when one month and year is selectd :

QFabian_3-1672861300980.png

 

Color  expression :

ONLY(

{<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>}


if(Category = 'A',RGB(255,0,0),
if(Category = 'B',RGB(0,76,153),
if(Category = 'C',RGB(0,102,204),
if(Category = 'D',RGB(220,20,60),
if(Category = 'E',RGB(0,0,255),
if(Category = 'F',RGB(0,0,128),
if(Category = 'G',RGB(0,128,255),
if(Category = 'H',RGB(160,160,160),
if(Category = 'I',RGB(255,51,51),
if(Category = 'J',RGB(255,215,0),
if(Category = 'K',RGB(255,0,0),
if(Category = 'L',RGB(0,191,255),
if(Category = 'M',RGB(178,34,34),
if(Category = 'N',RGB(139,0,0),
if(Category = 'O',RGB(0,110,0),
if(Category = 'P',RGB(220,20,60)
,RGB(200,200,200)))))))))))))))))
)

 

 

QFabian
QFabian
Specialist III
Specialist III

Hi @riclight89 , i tried to recreate your data and the chart, and i get this :

When there is a Month or Period selected, that period in chart is painted

QFabian_0-1672860485560.png

 

So, you need to put your set analysis expression in the color formula too.

{$<CreateYear=, CreateMonth=, CreateYearMonth = {">$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),-12),'YYYYMM'))<=$(=Date(Addmonths(Date#(max(CreateYearMonth),'YYYYMM'),0),'YYYYMM'))"}>}

 

 

This is my example, i tried to reduce the expression using variables :

vPeriod12 = =num(addmonths(date(CreateYearMonth, 'YYYYMM'), -12))

vPeriod1 = =max(CreateYearMonth)

QFabian_2-1672861253252.png

 

then using this chart expression  :

sum({<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>} Sales)

and seeing the chart like this, when one month and year is selectd :

QFabian_3-1672861300980.png

 

Color  expression :

ONLY(

{<CreateYear=, CreateMonth=, CreateYearMonth = {">$(vPeriod12)<=$(vPeriod1)"}>}


if(Category = 'A',RGB(255,0,0),
if(Category = 'B',RGB(0,76,153),
if(Category = 'C',RGB(0,102,204),
if(Category = 'D',RGB(220,20,60),
if(Category = 'E',RGB(0,0,255),
if(Category = 'F',RGB(0,0,128),
if(Category = 'G',RGB(0,128,255),
if(Category = 'H',RGB(160,160,160),
if(Category = 'I',RGB(255,51,51),
if(Category = 'J',RGB(255,215,0),
if(Category = 'K',RGB(255,0,0),
if(Category = 'L',RGB(0,191,255),
if(Category = 'M',RGB(178,34,34),
if(Category = 'N',RGB(139,0,0),
if(Category = 'O',RGB(0,110,0),
if(Category = 'P',RGB(220,20,60)
,RGB(200,200,200)))))))))))))))))
)

 

 

QFabian
riclight89
Contributor II
Contributor II
Author

@QFabian worked perfectly (even without creating the variables). Thank you!

QFabian
Specialist III
Specialist III

Excelent!, glad to help

QFabian