What else can the Qlik Peek function do?

  • How-Tos FAQs
  • October 26, 2020
Get Started Transforming Your Data in Snowflake

Qlik Peek function – what else can it do?

We most commonly use the peek() function in Qlik, to create variables from a set of data.

LET variable = Peek( field_name [, row_no[, table_name ] ])

For example, you are looping through datasets for a listed group of companies within a holding company, and you read the Company ID from a separate source to begin transactions…

LET vSource = PEEK('CompanyID', 0, 'Companies');

OR simple minDate maxDate from a Purchase dataset:

TempTable:
Load
   Date(Min(DateFirstPurchase),'DD/MM/YYY')AS MinDate,
   Date(Max(DateFirstPurchase),'DD/MM/YYYY')AS MAXDate
Resident Customers;

Let vMinVar=Peek('MinDate');
Let vMaxVar=Peek('MaxDate');

So you may ask? Why use LET instead of SET, when creating these variables? 

A SET is taken literally and what is to right of the equals sign is stored as the value

A LET first evaluates the expression on the right side of the “=” sign.

Since peek() requires evaluation, it cannot be taken literally.

 

What else is peek() used for?

  • Calculating values, such as cumulative totals:

Qlik peek function-3

In this example. To evaluate cumulative totals, we can use the peek() function:

Load CustID,
      [Sales Rep],
      [Sale Total],
       peek([Sale Total],-1)+[Sale Total] as CumlutiveTotal
From
[SamepleData\CustomerSales.xlsx]
(ooxml, embedded labels, table is Sheet1);
  • Duration between events.

Similarly to cumulative sales, one may wish to track the timestamp from one row of data to the next.

Tickets:
Load SR_Number,
     [Reported Date],
     peek ([Reported Date]) as PreviousDate
From
[SampleData\SA_RemedyTickets.xlsx]
(ooxml, embedded labels, table is QVResult);

One can then calculate the duration between events.

How does that differ from the Previous() function?

The key differentiator between Previous() and Peek() is…

Previous will return the data from the previous row in the source data , where Peek will return the previous row in the resultset, as it was stored in Qlik. Peek can additionally be directed to specific rows in alternative tables.

 


Up Next: Learn How to Get the Number of Months Between Two Dates in Qlik