Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Setting RGB

if(num(LifSafetyScore) >=  8 and (num(LifSafetyScore) <= 12 ,RED(),

if(num(lLifSafetyScore) >=  13 and (num(LifSafetyScore) <= 18 ,GREEN(),

if(num(LifSafetyScore) >=  18 and (num(LifSafetyScore) <= 22 ,Yellow()))))))

Above script is not working.How can write it ?

1 Solution

Accepted Solutions
sunny_talwar

Can you try this:

If(LifSafetyScore >=  8 and LifSafetyScore <= 12, Red(),

If(LifSafetyScore >= 13 and LifSafetyScore <= 18, Green(),

If(LifSafetyScore >= 18 and LifSafetyScore <= 22, Yellow())))

UPDATE: I think the issue might be related to the parenthesis

View solution in original post

9 Replies
Not applicable
Author

can you let us know where you are writing this script and what type of object you have creating?

any sample QVW that you can post would help us to understand the issue..

sunny_talwar

Can you try this:

If(LifSafetyScore >=  8 and LifSafetyScore <= 12, Red(),

If(LifSafetyScore >= 13 and LifSafetyScore <= 18, Green(),

If(LifSafetyScore >= 18 and LifSafetyScore <= 22, Yellow())))

UPDATE: I think the issue might be related to the parenthesis

Anonymous
Not applicable
Author

You seem to have too many parentheses. Try removing the ones in bold from below.

if(num(LifSafetyScore) >=  8 and (num(LifSafetyScore) <= 12 ,RED(),

if(num(lLifSafetyScore) >=  13 and (num(LifSafetyScore) <= 18 ,GREEN(),

if(num(LifSafetyScore) >=  18 and (num(LifSafetyScore) <= 22 ,Yellow()))))))

Anonymous
Not applicable
Author

Hi Pavana,

Maybe parenthesis issues:

if(num(LifSafetyScore) >=  8 and num(LifSafetyScore) <= 12 ,RED(),

if(num(lLifSafetyScore) >=  13 and num(LifSafetyScore) <= 18 ,GREEN(),

if(num(LifSafetyScore) >=  18 and num(LifSafetyScore) <= 22 ,Yellow() )))

Maurice

Anonymous
Not applicable
Author

I  agree  with Sunny T , the issue might be  to the parenthesis.


if(num(LifSafetyScore) >=  8 and (num(LifSafetyScore) <= 12 ,RED(),

      if(num(lLifSafetyScore) >=  13 and (num(LifSafetyScore) <= 18 ,GREEN(),

            if(num(LifSafetyScore) >=  18 and (num(LifSafetyScore) <= 22 ,Yellow()

               )

         )

)

Regards.

engishfaque
Specialist III
Specialist III

Dear Pavana,

Try this one, I hope you are looking for that one:

if(num(LifSafetyScore) >= 8 and (num(LifSafetyScore) <= 12), RED(),

  if(num(lLifSafetyScore) >= 13 and (num(LifSafetyScore) <= 18), GREEN(),

       if(num(LifSafetyScore) >= 19 and (num(LifSafetyScore) <= 22), Yellow())))

Kind regards,

Ishfaque Ahmed

jonathandienst
Partner - Champion III
Partner - Champion III

The num()* function does nothing here, so you can remove it. You can also reduce the number of conditionals, so the expression becomes much simpler:

if(LifSafetyScore >= 8,

  If(LifSafetyScore <= 12 ,Red(),

  if(LifSafetyScore <= 18 ,Green(),

  if(LifSafetyScore <= 22 ,Yellow())))

)

* Num() is a formatting function, and it does not affect the underlying value. The comparisons are on the underlying values so they are not affected in any way by the Num().

EDIT - minor correction to the expression

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

if(num(LifSafetyScore) >=  8 and (num(LifSafetyScore) <= 12 ,RED(),

if(num(lLifSafetyScore) >=  13 and (num(LifSafetyScore) <= 18 ,GREEN(),

if(num(LifSafetyScore) >=  18 and (num(LifSafetyScore) <= 22 ,Yellow()))))))

jonathandienst
Partner - Champion III
Partner - Champion III

If the LifSafetyScore is not being recognised as a number, you may need the Num#()

Num#(<a string>) is the number interpretation function takes a string and outputs a dual number

Num(<a number>) is the number format function and takes a number and outputs a dual value formatted as specified

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein