Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
annegedal
Contributor II
Contributor II

Color line in line chart by trend

Hi 🙂

Objective
I have a line chart displaying effect scores pr. year for various departments. I would like each year to be colored (red, yellow or green), based on whether the score of one year is better or worse the the previous year. 

My failed attempt
I have written the code below in the color expression box:

if(
     (Sum({$<[year]={$(=Max([year]))}>}effect)) > (Sum({$<[year]={$(=Max([year])-1)}>}effect)), green(),
     if(
           (Sum({$<[year]={$(=Max([year]))}>}effect)) < (Sum({$<[year]={$(=Max([year])-1)}>}effect)), red(),
           yellow()
     )
)

Using the if structure above, the color should be green if the score is higher than the previoud year, the color should be red if the score is lower than the previous year and yellow if the score is the same. 


Problem
The returned line charts for different departments are as shown in the pictures attached to the question. 

The line charts do not seem to behave according to the if() structure. Sometimes the effect goes from lower to higher and is colroed red other times it is colored green. 

Also, years that are not the most recent year selected or the previous year connected to it just get a yellow color. This, I guess, is do to the MAX statement in the code. But I'm not experienced enough with the syntax to figure out how else to write it :0)

Question
How should i write the code to accomplish my objective?

1 Solution

Accepted Solutions
JordyWegman
Partner - Master
Partner - Master

Hi Anne,

See if you can import this application. Then you can see it!

I've used this formula:

IF(Sum(kapacitet) > Above(Sum(kapacitet)),Green(), IF(Sum(kapacitet) = Above(Sum(kapacitet)),Yellow(),Red()))

The above function does the comparison to the previous year.

Jordy

Climber

Work smarter, not harder

View solution in original post

6 Replies
JordyWegman
Partner - Master
Partner - Master

Hi Anne,

Do you have sample QVF for us? This makes it a bit easier to solve.

The problem is indeed the MAX because you are looking at 2019 only.

Jordy

Climber

Work smarter, not harder
annegedal
Contributor II
Contributor II
Author

Hi Jordy

I'm not realy sure how to make a qvf file, when i don't have qlik as a desktop app 😕

But my data looks like the dummie file attached file.

 

BR
Anne

JordyWegman
Partner - Master
Partner - Master

Hi Anne,

See if you can import this application. Then you can see it!

I've used this formula:

IF(Sum(kapacitet) > Above(Sum(kapacitet)),Green(), IF(Sum(kapacitet) = Above(Sum(kapacitet)),Yellow(),Red()))

The above function does the comparison to the previous year.

Jordy

Climber

Work smarter, not harder
annegedal
Contributor II
Contributor II
Author

Hi Jordan

Beautiful and simple! it works! 😄

QQ: If the data wasn't ordered by date, would the above() function still work?

BR 
Anne

JordyWegman
Partner - Master
Partner - Master

Hi Anne,

Great! Please mark it as solved. 

Yes, then it would also get the value above.

Jordy

Climber

Work smarter, not harder
annegedal
Contributor II
Contributor II
Author

ok.

thanks 🙂