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

Using variables in charts

I have a line chart. In one of the expressions I use symbols (Points) to represent it. I want each of these points to be painted with one color of another depending of some conditions.

Then I defined background color using this expression (method 1):

target_orders

which is a variable that I have defined as below:

=if(numOrders < 10, Green(), If(numOrders >= 10 and numOrders <= 50, Yellow(), Red()))

and numOrders is another variable as below:

=sum({$<[Order Type] = {'A'}>}if([quantity] > 20000.0, 1,0))

but it seems background color is not correctly being displayed for each point in the chart.

Method 2:

However if I put the full expression as background color as below (without using variables):

=if(sum({$<[Order Type] = {'A'}>}if([quantity] > 20000.0, 1,0)) < 10, Green(), If(sum({$<[Order Type] = {'A'}>}if([quantity] > 20000.0, 1,0)) >= 10 and sum({$<[Order Type] = {'A'}>}if([quantity] > 20000.0, 1,0)) <= 50, Yellow(), Red()))

then each point is being displayed with the correct color.

So why QlikView is interpreting it differently if I use method 1 or method 2?

I would like to use variables as expression is clearer and readable than putting the full  expression in method 2.

How can I obtain the same results as method 2 using variables in method 1?

1 Solution

Accepted Solutions
marcus_sommer

I think your variables should look like:

$(target_orders)

if($(numOrders) < 10, Green(), If($(numOrders) >= 10 and $(numOrders) <= 50, Yellow(), Red()))

- Marcus

View solution in original post

5 Replies
sunny_talwar

May be you will need to play around with dollar sign expansion or try adding or removing equal sign from the variable definition.

Not applicable
Author

Doing this seems the behaviour is the same as method 2:

Method 1:

Background color expression:

$(=target_orders)

which is a variable that I have defined as below:

if($(=numOrders) < 10, Green(), If($(=numOrders) >= 10 and $(=numOrders) <= 50, Yellow(), Red()))

and numOrders is another variable as below:

sum({$<[Order Type] = {'A'}>}if([quantity] > 20000.0, 1,0))

The problem now is that all the symbols (points) are being painted with the same color.

sunny_talwar

Would you be able to share a sample?

marcus_sommer

I think your variables should look like:

$(target_orders)

if($(numOrders) < 10, Green(), If($(numOrders) >= 10 and $(numOrders) <= 50, Yellow(), Red()))

- Marcus

Not applicable
Author

I cannot as it is confidential (work material). But for example, I have a line chart with one expression. This expression is being represented with point symbols (not line). Then depending on some conditions I want each points of the same expression to be painted with red, yellow or red color. Is it possible to paint each point of the same expression with different colors based on condition? I think this is the problem, in the same expression maybe it is not possible so all the points in my case are painted with the same color. How can I do this? better to add another post for this.