Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I've got a stacked bar chart with two dimensions (First, Second) and one measure (Measure).
The chart's second dimension (Second) is specified by an expression and is based on the value of a variable:
fx = if ($(myVar)=1, [DimensionX], [DimensionY])
For the coloration I would like the colors to be based on the value(s) of the active dimension; ie, I need to dynamically color by dimension.
Under the Colors setting I chose Custom > By Dimension and specified the above expression in the Dimension expression box.
This does not work. All of the colors turn to gray!
Some observations from playing around:
Thanks for any suggestions.
I've consulted with Qlik support. They've verified that it's a bug in Qlik and has been addressed in the latest version.
Hi Steven, color by expression expect a color code, ie:
If(ThisYearSales>LastYearSales, Green(), RGB(255,0,0))
In your case:
if ($(myVar)=1, Color1, Color2)
https://help.qlik.com/en-US/sense/November2017/Subsystems/Hub/Content/Colors/color-by-expression.htm
To keep a color for each dimension value you can try with:
if ($(myVar)=1, Color(FieldIndex('DimensionX', [DimensionX])), Color(FieldIndex('DimensionY', [DimensionY])))
Just to be clear, I'm using the expression function under Color by Dimension, not Color by Expression.
And it seems that (at least in this version of QlikSense) anything but a single dimension name; eg [Dimension1], in the expression box causes loss of all color.
It needs to return only one value and Aggr() can return more than one value, set the expression as:
=if($(myVar)=1, [DimensionX], [DimensionY]) // With the starting '='
This doesn't works?
I agree what you've specified should work. But it doesn't.
The only way I can make it work is if I express it as such:
$(=chr(39)&if(myVar=1,'DimensionX','DimensionY')&chr(39))
Which to me seems like a unnecessarily complicated expression.
It works for me, have you set the starting '='?
My chart is a little more complicated. I've modified your example to include an instance of what I'm seeing.
I cannot get proper segment colors to appear without doing what I've described earlier.
Perhaps you can make it work? I appreciate your assistance.
I tried "=if($(var2)=1,D3,D4)" and seems to work, can you try?
Seems to work in this instance, let me apply it to my original application and see.
One final modification: Gave the fields slightly more complex names and qualified them. This is closer to our actual app now.