Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
vignesh_s
Creator
Creator

Peek function

can any one explain the effective or advanced way of using peek function

3 Replies
prat1507
Specialist
Specialist

Peek() finds the value of a field in a table for a row that has already been loaded or that exists in internal memory. The row number can be specified, as can the table.


peek( fieldname [ , row [ , tablename ] ] )

Returns the contents of the fieldname in the record specified by row in the input table tablename. Data are fetched from the associative QlikView database.

Fieldname must be given as a string (e.g. a quoted literal).

Row must be an integer. 0 denotes the first record, 1 the second and so on. Negative numbers indicate order from the end of the table. -1 denotes the last record read.

If no row is stated, -1 is assumed.

Tablename is a table label without the ending colon. If no tablename is stated, the current table is assumed. If used outside the load statement or referring to another table, the tablename must be included.

Examples:

peek( 'Sales' )
returns the value of
Sales in the previous record read ( equivalent toprevious(Sales) ).

peek( 'Sales', 2 )
returns the value of
Sales from the third record read from the current input table.

peek( 'Sales', -2 )
returns the value of
Sales from the second last record read into the current input table.

peek( 'Sales', 0, Tab1 )
returns the value of
Sales from the first record read into the input table labeled Tab1.

Load A, B, numsum( B, peek( 'Bsum' ) ) as Bsum...;
creates an accumulation of B in Bsum.


How to use Peek function?



mdmukramali
Specialist III
Specialist III

Demlet
Contributor III
Contributor III

Hi Vignesh,

Peek is effective in a bunch of ways. One example would be for a custom pagination loop within a REST connection.

Below I am grabbing the "x-total-count" of ALL the records from the source "120,000" from the header. Using peek - I then peek into the totalTable's "x-total-count" value and set that as my new "total" variable. Additionally with some limitations you can "peek" into other tables and use specific values from them locally.

totalTable:

SQL SELECT

"X-Total-Count" AS "X-Total-Count_u1"

FROM JSON(wrap on) "_KEY_response_header";

Let total = peek('X-Total-Count_u1',0,'totalTable');

DROP TABLE totalTable;

Let totalfetched = 0;

Let startAt = 0;

Let pageSize = 10000;

for startAt = 0 to total

TRACE "startAt: " $(startAt);



Hope this helps


- Derek