Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
rennesia
Contributor III
Contributor III

How to use PEEK-function with condition?

peek.jpg

In my application, I want to fill unknown datafields with historical values from the last row with the same TagID (first column). In the actual situation the positions with the red values are empty. I filled in the red values to show what they should be.

A normal PEEK-function can use the data from a fixed previous record, but how to program the condition to copy from a previous record with a certain condition?

1 Solution

Accepted Solutions
felipedl
Partner - Specialist III
Partner - Specialist III

Hi,

For the peek to work, you'll have to order your data.

In this case, order it by TagID and TimeStamp so you can have a table with the historic view, by TagID. like so:

orderedTable:

Load *,

         if(peek(TagID)=TagID,peek(MTBF),MTBF) as MTBF

Resident dataTable

order by TagID,TimeStamp;

Next, you use the peek() statement to check something like this:

if(peek(TagID)=TagID,peek(MTBF),MTBF)

this if will verify if the previous tag ID is the same as the current one and then get the according MTBG value.

Hope it helps,

Felipe.

View solution in original post

3 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

Hi,

For the peek to work, you'll have to order your data.

In this case, order it by TagID and TimeStamp so you can have a table with the historic view, by TagID. like so:

orderedTable:

Load *,

         if(peek(TagID)=TagID,peek(MTBF),MTBF) as MTBF

Resident dataTable

order by TagID,TimeStamp;

Next, you use the peek() statement to check something like this:

if(peek(TagID)=TagID,peek(MTBF),MTBF)

this if will verify if the previous tag ID is the same as the current one and then get the according MTBG value.

Hope it helps,

Felipe.

rennesia
Contributor III
Contributor III
Author

Almost an too easy solution, but it works fine! Thanks Felip!

felipedl
Partner - Specialist III
Partner - Specialist III

Glad it helped