Qlik Sense: How to set custom colors by measure in a bar chart
This example was worked out using Qlik Sense Desktop 1.1.0
Thank you to Christof Schwarz for this solution.
For this example, the dimension is "Segment" and the measures are "Sales", "Quota", and "Expenses". The requirement is a bar chart with Sales in green, Quota in blue, and Expenses in red.
Normally with a Qlik Sense bar chart, I would have one dimension: Segment, and three measures: Sum(Sales), Sum(Quota), and Sum(Expenses). However, for custom colors, I need to have two dimensions and one measure. The second dimension and the one measure are using the ValueList() function.
See attached qvf file "BarChartColorByMeasure.qvf". It has two sheets. Both sheets have a bar chart displaying the same information. The first shows coloring without customizing. The second sheet shows customized coloring.
Here's what I did. I made a bar chart...
Added a second dimension:
Label: Account Type
Added a measure:
Sorting in this example is by Segment then by Account Type then by Amount, with Account Type as descending alphabetical.
Now to set the colors. I went to "Appearance" then "Colors and Legend", then turned off Auto for Colors. In the dropdown, selected "By expression". I entered this expression:
I made sure the check box was checked for "The expression is a color code".
Please note: You will not able to show the chart's legend. This is a known limitation. For right now in Qlik Sense, the color legend is not displayed when using "The expression is a color code".