Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
blakeB
Contributor II
Contributor II

Conditional Color based on previous month's value

Hi Everyone,

I imported an excel table (column 1: month, column 2: sales) and wanted to know if there was a way to conditional color based on the previous month's sales figure (for example: if previous month sales is less than current month sales, green, otherwise red).

I'm using: 

sum({<Month={'$(=max(Month))'}>} [Sales])
 
to reference the most recent month's sales entry to display in the KPI, and wanted to display the metric red or green based on previous month. 
1 Reply
H_Julian
Contributor III
Contributor III

A Qlick Sense KPI's Text colour can be set by function.

In your example you can simply set the function as following:

If( sum({<Month={'$(=Num(max(Month)))'} >sum({<Month={'$(=Num(max(Month)-1))'},rgb(0,255,0),rgb(255,0,0))

However, this solution will create a problem on January, since this is the first month and you would like to compare it to December. 

You could instead define a new Dimension within the Script editor which sets continuous numbers for every month/year.

For example, 12.2018 would be 1, 01.2019 would be 2, 02.2019 would be 3 and so on and replace Month in the above described set analysis

with the new Dimension.

Best Regards Julian