Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
prananellutla
Creator
Creator

Color mix expression with if condition

Hi I am trying to give a gradient color using if stmt and color mix func to a barchart iam working on. can i get some help here. I cant get the code right its not working for me.

if(year([Applied Date])=year(today()), colormix1(rank(total column(1))/noofrows(TOTAL), rgb(255, 0, 102), rgb(255, 204, 224)))

bar.png

color expression.png

this is my data

 

year([date field])month([date field])measure
2017May67,718
2017Jun84,459
2017Jul84,692
2017Aug86,536
2017Sep75,714
2017Oct83,916
2017Nov78,621
2017Dec54,663
2018Jan105,698
2018Feb87,395
2018Mar92,941
2018Apr77,395
2018May54,646

thanks

1 Solution

Accepted Solutions
sunny_talwar

Try this

If(Year(Max(Date)) = Year(Today()), ColorMix1(Rank(TOTAL Sum([#measures]))/NoOfRows(TOTAL), RGB(255, 0, 102), RGB(255, 204, 224)))


Capture.PNG

View solution in original post

7 Replies
sunny_talwar

Would you be able to share your qvf file to check this out and play around with a little bit?

prananellutla
Creator
Creator
Author

HI Sunny, Iam working on the enterprise version. Let me create the qvf in desktop version and send it over.

prananellutla
Creator
Creator
Author

Hi Sunny here is the qvf.

how ever in the actual app, I have a calculated measure to show 12 month rolling period. I assume it doesn't matter how iam using my measure calculation as long as you have workable chart and data?

let me know if this works. thanks for your time and help on this .

prananellutla
Creator
Creator
Author

hi Sunny I am tying to give diff gradient color for each year .

if([date=year(today()), colormix1(rank(total column(1))/noofrows(TOTAL), rgb(255, 0, 102), rgb(255, 204, 224)),

if(date=year(today())-1,colormix1(rank(total column(1))/noofrows(TOTAL), rgb(204, 51, 0), rgb(255, 102, 51))))

sunny_talwar

Try this

If(Year(Max(Date)) = Year(Today()), ColorMix1(Rank(TOTAL Sum([#measures]))/NoOfRows(TOTAL), RGB(255, 0, 102), RGB(255, 204, 224)))


Capture.PNG

prananellutla
Creator
Creator
Author

Hi Sunny thankyou for working on this. Re: Applying Color gradient for Bar Chart in Qliksense  discussion helped be to understand the concept iam looking for.

in the code , we should also consider the number of dimensions we are using in our visual , it will do the trick.

color expression.png

the exact code i used in my actual app is 

if([ Year]=year(today()), ColorMix2( (rank(total column(1))/(noofrows(TOTAL)/6))-1 ,rgb(0,112,200),rgb(142,180,227),rgb(198,217,241)),

if([Year]=year(today())-1,ColorMix2((rank(total column(1))/(noofrows(TOTAL)/6))-1,rgb(204, 204, 0), rgb(255, 255, 179),rgb(189,0,98))))

thanks again for looking into this.

sunny_talwar

Great ... I am glad you figured it out. Please close the thread by marking correct and helpful responses.

Best,

Sunny