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: 
FedericaQ
Contributor II
Contributor II

Write two IF statements in color by expression field

The Qlik documentation provides an example on how to color both background and text using two if statements in the color by expression field: 

Example: Coloring table object font and background by measure value.

if(Sum([Sales]) < 10000, 'red', green())

if(Sum([Sales]) > 200000, 'gold', )

In this example, two expressions are used to color the background and text of the Sales column. Measure values in Sales that are lower than $10000 have a red background color, all other values have a green background. In addition, the values that are higher than $200000 have the text color 'gold'.

Source 

Now, I cannot find a way to insert two IF statements inside a color by expression field. I have tried putting them in this way:

=if(num([3.7] + [11]) <5, 'red', green())

=if(num([3.7]+[11])>15, 'red')

but none of the two expressions has an effect (I don't get anything green nor red). If I remove the equal sign, I get "Error in expression, Garbage after expression: 'if'". So, how do I do that? What does the documentation mean exactly?

For clarity, what I want to do is to set both the background and label color for a map point layer.

Labels (2)
5 Replies
rdelagarde
Contributor III
Contributor III

Hi,

Simply by concatenating multiple IF statements:

If(/*your number*/ < 5, 
   Red(), //red if < 5
   If(/*your number*/ > 15,
      Green(), //green if > 15
      Yellow() //yellow if >= 5 and <= 15 
   )
)

 

 

FedericaQ
Contributor II
Contributor II
Author

Thank you for your suggestion, but that code only changes the background color, not the label color.

rdelagarde
Contributor III
Contributor III

The Qlik example is on a table object. There are two fields for the colors on a table object:

Capture web_14-1-2022_102258_jfoy9lajt8qo68u.eu.qlikcloud.com.jpeg

 

 

 

 

I don't know if it's possible to do the same with a map...

FedericaQ
Contributor II
Contributor II
Author

I see, then that must be the problem. Thank you.

Joseph_Musekura
Support
Support

Hi @FedericaQ ,
Did you check what result do you have when using num([3.7] + [11]) I  mean before using it in a If statement  i.e. result < 5

Regards,