Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variable question

I have a table TABLE1 with two columns, COLUMN1 and COLUMN2

COLUMN1COLUMN2
RED10
GREEN0
BLUE0
PURPLE0

I am setting a variable in the script as below:

Let vStatus = Peek("COLUMN1",0,TABLE1);

I am trying to use this variable in text box background color as a calculated color as below

if(vStatus>>0,Red(),Green())

I always get green background for the text box. I tried hardcode value 10 in the let statement and that changes the color to Red. So somehow the Let statement with peek is not working. Need some advice and help!

Thanks!

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

You can use peek outside a Load statement, but you need to specify the field name and the table name with single quotes:

Let vStatus = Peek('COLUMN1',0,'TABLE1');

This Let statement will assign the text 'RED' to the variable vStatus, butI am not sure I understand how you want to use it...

If you want to specify the color based on the value in field COLUMN2 - i.e. different colors in different lines of a table - then you should use the following color expression:

if(COLUMN2>0,Red(),Green())

or if you consider the possiblity of COLUMN2 having several possible values:

if(count(distinct COLUMN2)=1,

   if(COLUMN2>0,Red(),Green()),

    lightgray() )

HIC

View solution in original post

4 Replies
whiteline
Master II
Master II

You cann't use peek outside LOAD statement(below).

Use this function:

FieldValue(fieldname , n )

Returns the field value found in position n of the field fieldname (by load order). fieldname must be given as a string value, e.g. the field name must be enclosed by single quotes. The first field value is returned for n=1. If n is larger than the number of field values, NULL is returned.

hic
Former Employee
Former Employee

You can use peek outside a Load statement, but you need to specify the field name and the table name with single quotes:

Let vStatus = Peek('COLUMN1',0,'TABLE1');

This Let statement will assign the text 'RED' to the variable vStatus, butI am not sure I understand how you want to use it...

If you want to specify the color based on the value in field COLUMN2 - i.e. different colors in different lines of a table - then you should use the following color expression:

if(COLUMN2>0,Red(),Green())

or if you consider the possiblity of COLUMN2 having several possible values:

if(count(distinct COLUMN2)=1,

   if(COLUMN2>0,Red(),Green()),

    lightgray() )

HIC

whiteline
Master II
Master II

Hi, Henric

Thanks, will keep in mind (Peek).

Not applicable
Author

Hi ,

Please check the Qlikview Reference manual for help on Peek() function. And it's clearly mentioned that peek() can be used outside the LOAD statement but with the TABLE name reference. The peek function searches for the Tables in the Qlikview database(which are already loaded in the qvw file). Peek() function syntax is wrong in your situation.

As suggested by Henric you can make use of the column in the table for changing the color based on value in the field rather than making use of variable.

- Sri