12 Replies Latest reply: Jan 31, 2016 9:06 PM by Sunny Talwar

# Nested if for color expression

Howdy, I am trying to make a conditional if statement for a color expression in qlik sense. It goes something like this:

if((decile = '1' or decile = '2' or decile = '3' or decile = '4'), green(),

if (decile = '5' or decile '6' or decile = '7')

,blue()

if(decile = '8' or decile = '9' or decile = '10')

,red())

but for some reason I am still getting an error on parenthesis, 'expecting a ')'. Any assistance?

• ###### Re: Nested if for color expression

in the tirdh row ypou need a "," at end of blue()

if((decile = '1' or decile = '2' or decile = '3' or decile = '4'), green(),

if (decile = '5' or decile '6' or decile = '7')

,blue(),

if(decile = '8' or decile = '9' or decile = '10')

,red())

and you need add two ) at the end

See:

if ((decile = '1' or decile = '2' or decile = '3' or decile = '4'), green(),

if ((decile = '5' or decile '6' or decile = '7'), blue(),

if ((decile = '8' or decile = '9' or decile = '10'), red())))

• ###### Re: Nested if for color expression

Hi,

Thank you for this, I still receive an error with this. Decile is a number. Still the ')' expected error

• ###### Re: Nested if for color expression

Try like this

if((decile  <= 4

, green()

, if (decile >= 5 and decile <=7

,blue()

, red()

)

)

• ###### Re: Nested if for color expression

Stefan do you think we can go away with  >= 5 from your proposal? Like the below

If(decile  <= 4, green(),

If(decile <= 7, blue(), red()))

• ###### Re: Nested if for color expression

Sure, you are right!

• ###### Re: Nested if for color expression

A lot of time people has asked me if the above as true as what you have proposed and I have always wondered if there is a time when they won't give the same result. I guess never

• ###### Re: Nested if for color expression

Unless decile is not an integer ...

• ###### Re: Nested if for color expression

Right, that is true

• ###### Re: Nested if for color expression

Another one would be:

If(Match(decile, 1, 2, 3, 4), Green(),

If(Match(decile, 5, 6, 7), Blue(),

If(Match(decile, 8, 9, 10), Red())))

• ###### Re: Nested if for color expression

Or  like this

Pick(decile

, green(),green(),green(),green()

,blue(),blue(),blue()

,red(),red(),red()

)

• ###### Re: Nested if for color expression

thank you, this worked.

• ###### Re: Nested if for color expression

Awesome, I am glad I was able to help