Qlik Sense – Color by expression

  • How-Tos FAQs
  • November 24, 2020

Qlik Sense – Color by expression

“I have a line chart in Qlik Sense that I would like to define the color of each line representation in.”

An example is a chart that displays Monthly Sales for the Current Year with a comparative Sales line for the previous year. Additionally, we want another line for the Budget Amount in the same period as current Sales.  

So we want to display each of these dimensions in a specific color. Sometimes just for the flexibility to repeat these same colors and patterns in an additional, similar, or comparative format. How do we do this in Qlik Sense?

The key is using a Synthetic Dimension that can effectively “MAP” or “PIVOT” color to this dimension, with some predefined, so-called  “hard-coded” values within a ValueList()


We extend this further by using the dates as a single measure with the value to be displayed in each dimension:

if(  ValueList('CurrYear',;PrevYear','Budget')='Budget', SUM({<Year={2021}>}Budget),

if(  ValueList('CurrYear',;PrevYear','Budget')=’PrevYear', SUM({<Year={2019}>}Sales),

if(  ValueList('CurrYear',;PrevYear','Budget')='CurrYear', SUM({<Year={2021}>}Sales)


Remember.. These dates can also be created as a variable for current and all previous years

SET vCurrYear = Year(CURRENT_DATE);

SET vPrevYear = (vCurrYear-1);

if(  ValueList('CurrYear',;PrevYear','Budget')='Budget', SUM({<Year={$(vCurrYear)}>}Budget),

if(  ValueList('CurrYear',;PrevYear','Budget')=’PrevYear', SUM({<Year={$(vPrevYear)}>}Sales),

if(  ValueList('CurrYear',;PrevYear','Budget')='CurrYear', SUM({<Year={$(vCurrYear)}>}Sales)


Define the Color by each Expression with the colors you want for the individual Dimension:

if(  ValueList('CurrYear',;PrevYear','Budget')='Budget', argb(80,80,80,80),

if(  ValueList('CurrYear',;PrevYear','Budget')=’PrevYear', argb(160,80,80,80),

if(  ValueList('CurrYear',;PrevYear','Budget')='CurrYear', Green()


This is how in Qlik Sense – Color by expression is achieved. It is a slightly extended and manual method to achieve a standard or specified color pattern for specific items; however, it is effective and reliable. 

Up Next: Learn GeoAnalytics and Google Maps Extensions for Qlik

Related Posts


Qlik Number Formatting

  • How-Tos FAQs
  • November 4, 2020

Qlik Date Conversion for SAP

  • How-Tos FAQs
  • October 28, 2020

Qlik resident load examples 

  • How-Tos FAQs
  • November 3, 2020