Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

visualssinziana
New Contributor III

Create nested if statements in color by expression

I created a positive-negative bar chart and I would like to implement 2 colors: green for positive values and red for negative values for example.

Positive negative bar.jpg

I have used two measures to obtain this chart a Min(value) and a Max(value), so when I insert a color expression I have something like this:

=If(Min(Value) < 0, Green(), Red()) but I would like to create a nested if statement something like:

=If(Min(Value) < 0, Green(), Red(),

     If(Max(Value) > 0, Green(), Red())

But I'm not sure if I can use this approach in this case cause is not working. Any ideas how to create something like this?Thanks,

Capture1.PNG

1 Solution

Accepted Solutions
agigliotti
Honored Contributor II

Re: Create nested if statements in color by expression

I guess you can't because you have only one expression color to set for both measures.

To achieve what you want you should be able to set color expression for each measure.

10 Replies
omarbensalem
Esteemed Contributor

Re: Create nested if statements in color by expression

what's the expression you're using in your chart?

Highlighted
felipedl
Valued Contributor III

Re: Create nested if statements in color by expression

Hi Sinziana,

Instead of using min(Value) and max(value) for the color, use your expression for the color option (selected in blue in my screenshot).

something like:

if(sum([Compras Preço Custo])>0,Green(),Red()) // sum([Compras Preço Custo]) is my expression for the graph below).

In my case, it gives me

Sample.png

Since your expression is if(min(Value)<0,Red(),Green()), its always evaluating true, because your min value for the dataset is lower than 0 (zero) giving all bars the red color.

agigliotti
Honored Contributor II

Re: Create nested if statements in color by expression

why not using simple expression as below

=if( Sum(Value) < 0, Red(), Green() )

?

visualssinziana
New Contributor III

Re: Create nested if statements in color by expression

The thing is my chart is created with 2 columns of data united: a list of values that I want to see below the line (I gave them the minimum function) and a list of values that I want to display above the line (I gave them Maximum function).

That's why the syntax doesn't work in my case because I have 2 stacked measures and your syntax works with a measure (sum([Compras Preço Custo]) and 2 colors .

Maybe you have another idea how to display my data above and below the line O without the trick of Min and Max function. All values are on the same dimension.

If color.jpg

agigliotti
Honored Contributor II

Re: Create nested if statements in color by expression

why do you need two values for each year ?

visualssinziana
New Contributor III

Re: Create nested if statements in color by expression

There are two series of data (two values) united in the same graph because they show different things: a series shows how many processes ended in each year and the second how many processes started.

agigliotti
Honored Contributor II

Re: Create nested if statements in color by expression

what about your color request related to those series of data ?

what's exactly the logic you have in mind ?

visualssinziana
New Contributor III

Re: Create nested if statements in color by expression

I want the values above in blue (Positive series of values) and the values below (Negative series of values) in red for example.

agigliotti
Honored Contributor II

Re: Create nested if statements in color by expression

I guess you can't because you have only one expression color to set for both measures.

To achieve what you want you should be able to set color expression for each measure.