Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Simple Question about max() function

Hi Everybody,

I want to change the color in bar chart as the following :

Red for the higher value and Green for the lower value

So, under bar chart properties >> Expressions >> "+" >> Background Color >> Definition I(ve written this :

if(data%Table-above(data%Table)=max(data%Table-above(data%Table)),LightRed()) but It doesn't work

However, if I write this :

if(data%Table-above(data%Table)=23,LightRed()) it works

Do you know what is wrong with max function ?

Thank you

1 Solution

Accepted Solutions
matt_crowther
Luminary Alumni
Luminary Alumni

In teh expression of the Background colour setting of your expression use the 'rank()' function to determine the top and bottom values and assign the colours required in much the same way as your initial example.

This method works for me and you don't need to get bogged down in variables.

Something along the lines of (unchecked):

=if(rank(Sum(Sales))=1,rgb(198,255,198),if(ranksum(Sales),4)=1,rgb(255,198,198),rgb(255,255,255)))

If you get stuck have a look in the help file.

Hope that helps,

Matt - Visual Analytics Ltd

View solution in original post

6 Replies
sushil353
Master II
Master II

Dear jeremy02,

first calculate the max function and store the value in a variable and then apply your expression.

I hope that might work.

TC 🙂

Not applicable
Author

Hi Sushi,

First, thank you to help me.

As you told me I have to do the following :

max_value = max(data%Table-above(data%Table))

if data%Table-above(data%Table)= max_value, lighred()

My question is to know where to do the first line ? Because I think that we can just add 1 expression at the same time no ?



Not applicable
Author

ok the problem is that the expression "data%table - above(data%table)" return nothing

How can I get a field with this : NewField = Field(i) - Filed(i-1)

Thank you

Not applicable
Author

Good Morning Everybody,

I've a field with counter number (for example Index) :

Index

123
160
176
180
250

If I do : "Variable = Max(Index)" I get 250 this is ok but if I do "Above(Index)" I get :

Above(Index)

-
123
160
176
180
250

and Max(Above(Index)) returns this '-'

The aim is to make a difference between Index and Above(Index)

Thank you

matt_crowther
Luminary Alumni
Luminary Alumni

In teh expression of the Background colour setting of your expression use the 'rank()' function to determine the top and bottom values and assign the colours required in much the same way as your initial example.

This method works for me and you don't need to get bogged down in variables.

Something along the lines of (unchecked):

=if(rank(Sum(Sales))=1,rgb(198,255,198),if(ranksum(Sales),4)=1,rgb(255,198,198),rgb(255,255,255)))

If you get stuck have a look in the help file.

Hope that helps,

Matt - Visual Analytics Ltd

Not applicable
Author

I've a question Matt :

This is the Field named "Index" and the return values of the expression rank(Index)

Is it normal that I get exactly the same ranking if I write rank(Index,0) or rank(Index,1) or rank(Index,2) ... ? According to the help no, do you knwo the reason ?

Thank you