Qlik Community

Qlik Sense Documents

Qlik Sense documentation and resources.

Announcements
QlikWorld 2022, LIVE in Denver CO., May 16-19, 2022. REGISTER NOW TO RECEIVE EARLY BIRD PRICING

Peek Function Understanding & null data behavior

cancel
Showing results for 
Search instead for 
Did you mean: 
Olip
Creator
Creator

Peek Function Understanding & null data behavior

My recent experience with Peek function draws a huge parallel to that old friend whom you thought you knew, but turned out to be different. Enough of the melodrama

Peek function as we all by definition is "finds the value of a field in a table for a row that has already been loaded or that exists in internal memory." Keywords as I underlined are table that been loaded and exists in the memory; this has been my understanding until I was caught up in the scenario which involved multiple tables and variables.

I discovered that Peek works only for the last table loaded if multipl !e tables are loaded preceding the function. To illustrate the same, I have attached the App ("Peek Mystery"), where the variables vQuarterLlimit & vQuarterUlimit were not getting set correctly or rather getting set alternatively. After spending a good amount of time scratching my head, since overall code involved other variables and multiple peek functions (however using fields from the a single table), I could finally figure out that it was :

  • Peek would always set the variable for the table which was loaded second(in this example) or rather before the peek function
  • If the peek functions are called in right after the individual table loads ,it works fine

See the attached App for reference and share your expert opinion.

I will continue to spend some more time on this and update my findings!

Thanks,

A

Tags (1)
Comments
marcus_sommer
MVP & Luminary
MVP & Luminary

I think you missed the third parameter for the peek-function which defines the tablename from which the value should be taken. Only if there is no third parameter it will take the current load-table respectively the last loaded table.

Here within the community are already several very good postings which explain this feature, for example:

Peek() or Previous() ?

Peek() vs Previous() – When to Use Each

- Marcus

Olip
Creator
Creator

Not the case. See the App code:

Let vQuarterUlimit=Peek('UpperQuarterEndDt',0,"TempUQuarterDate");

Let vQuarterUlimit=Peek('LowerQuarterEndDt',0,"TempUQuarterDate");

Even I was hung up on syntax and other parts of my overall code. But turned to be last table loaded into memory.

0 Likes
sunny_talwar

This seems to work...

Let vQuarterUlimit=Peek('UpperQuarterEndDt',0,'TempUQuarterDate');

Let vQuarterLlimit=Peek('LowerQuarterEndDt',0,'TempLQuarterDate');

marcus_sommer
MVP & Luminary
MVP & Luminary

The tablename needs to be wrapped with single-quotes and not double-quotes which qliks would interpret as fields. Further field- and tablenames are case-sensitive - therefore make sure that they reall fit. In your example above are both variablenames identically and would overwrite eachother.

- Marcus

Olip
Creator
Creator

Peek Issue.jpgHey stalwar1‌ Single quotes or '[]' does not make a difference.

As pointed out by Marcus, there were a few code errors in the sample App attached.

I have fixed those and uploaded the latest app.

Have a look; till now my theory stands that it can look into the last table loaded.

0 Likes
Olip
Creator
Creator

Hey Marcus - I have uploaded the Sample App with fixed code to explain the scenario.

0 Likes
sunny_talwar

Not sure what is different, but when I load, I see this

Capture.PNG

0 Likes
Olip
Creator
Creator

Yes indeed single quotes made it work. But I am bit unclear of the way this function works.

I see another strange problem, Peek seems to not work on the first row condition when loading distinct records from a qvd i.e Let vUQuarter=Peek('UpperQuarter',0,'TempQuarterNum'); does not set the value but Let vUQuarter=Peek('UpperQuarter',1,'TempQuarterNum'); works. With the distinct load applied only one row is loaded into the table 'TempQuarterNum'.

(

LOAD Distinct

ENT_DIM_QTR_NUM as UpperQuarter,

ENT_DIM_QTR_NUM-6 as LowerQuarter

FROM [XXXX\XXDAY_D.qvd]

(qvd)

where W_CURRENT_CAL_QTR_CODE='Current' ;

)

It works in the following cases:

  • when I do not do a distinct load of the records from the QVD, which is the same dataset repeated 93 times
  • it also works when I mark last record position -1 or if only the field is called vUQuarter=Peek('UpperQuarter'); which is essentially the last read record

Also, this behavior of not being able to peek on record 0 does not occur when same qvd data is loaded from an excel file instead.

Any ideas why?

0 Likes
sunny_talwar

Can you share the complete script you have tried?

0 Likes
Olip
Creator
Creator

Ok it was due to null records in the QVD file!

Hence, the query would load multiple null records along with the legit record.

But would not be visible when row count was run.

I 'm again friends with Peek function I guess for now

Thanks for all your help!

0 Likes
Version history
Last update:
‎2018-02-20 10:50 AM
Updated by: