Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Peek function

Hi ,

Is it possible to use the peek function with variable. Need to dynamically specify the column position(Row number which the data has to be picked)

For e.g

i can define in loop like this

let e=1

do while e<=10

let c=  peek('column',$(e),'Table' )

let e=e+1;

loop

6 Replies
deepakk
Partner - Specialist III
Partner - Specialist III

hi XXX,

Yes its possible. but you need to add e variable to c. Hence you will have multiple variable.

PFA.

Deepak

Not applicable
Author

Thanks for your response Deepak.

It is fine for the first value not for the second value.It is not storing the next value .

  Is there any way i can store like this

   Let vRecord= Load id Resident table; 

Please find my scrip i have used

Tabledata:

LOAD id,

,

Filelocation

FROM

(biff, embedded labels, table is Sheet1$);

Tabledetails:

LOAD max(id)  as maxid

FROM

(biff, embedded labels, table is Sheet1$);

Let x=Peek('maxid' ,0,'Tabledetails');

Let a=1;

Do while a<=x

flocation:

Load  Filelocation  Resident Tabledata where id=$(a);

Let filocation= Peek('Filelocation' ,0,'flocation');

Finaltable:  

LOAD  *  FROM $(filocation);

let a=a+1;

loop

File location when a =1 it is fine .But for a=2 it is null. So the second row data is not getting loaded.  Please suggest

Not applicable
Author

Thanks for your response Deepak.

It is fine for the first value not for the second value.It is not storing the next value .

  Is there any way i can store like this

   Let vRecord= Load id Resident table; 

Please find my scrip i have used

Tabledata:

LOAD id,

,

Filelocation

FROM

(biff, embedded labels, table is Sheet1$);

Tabledetails:

LOAD max(id)  as maxid

FROM

(biff, embedded labels, table is Sheet1$);

Let x=Peek('maxid' ,0,'Tabledetails');

Let a=1;

Do while a<=x

flocation:

Load  Filelocation  Resident Tabledata where id=$(a);

Let filocation= Peek('Filelocation' ,0,'flocation');

Finaltable:  

LOAD  *  FROM $(filocation);

let a=a+1;

loop

File location when a =1 it is fine .But for a=2 it is null. So the second row data is not getting loaded.  Please suggest

deepakk
Partner - Specialist III
Partner - Specialist III

hi,

Because u need to create array of variable like below

fillocation$(a) = peek('FileLocation',$(a),flocation)

Not applicable
Author

I do something similar to this with for loops.  Not sure exactly how much this relates to what you want to do but here's an idea:

Tables:

FIRST 1 LOAD DISTINCT

     filename() as 'File',

     QVDNoOfFields('$(vPath)' & filename()) as 'Field Count'

FROM

(qvd);

For i = 1 to NoOfRows('Tables')

LET vFileName = peek('File',$(i)-1,'Tables');

LET vFieldCount=peek('Field Count',$(i)-1,'Tables');

QVDs:

FIRST 1 LOAD DISTINCT

     filename() as 'qvd',

     filetime() as 'qvd Time',

     date(left(filetime(),index(filetime(),' ')-1)) as 'qvd Date',

     qvdNoOfFields('$(vPath)' & filename()) as 'qvd Number of Fields',

     evaluate(filesize('$(vPath)$(vFileName)')/1048576) as 'qvd File Size (mb)',

     QvdNoOfRecords('$(vPath)$(vFileName)') as 'qvd No of Records'

FROM

$(vPath)$(vFileName)

(qvd);

Next

Not applicable
Author

XXX,

I believe this is the same concept as reading through a spreadsheet to create multiple variables for expressions.

You can adapt the code to fit the resident file.

http://community.qlik.com/message/115347#115347

Regards,

Rich