Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
bradsiebert
Contributor
Contributor

Peek Not Behaving as Expected

I am having an issue with Peek inside of an IF statement not behaving as expected.  Outside of an IF statement Peek works as expected.  I've included a simplified example where I am trying to fill in values for the Affirmed field with regards to the Category field.  I'm not sure if the Left Join may be having an effect on this.  Please see the attached qvw.

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

Try it in this way:

Test:
LOAD * INLINE [
RowNumber, Category, Affirmed
1, A, Yes
2, A
3, A, No
4, B
5, B, Yes
6, B, No
7, C
8, C, Yes
9, C, No
10, C
];

// NoConcatenate
Test2:
LOAD
RowNumber //, Category
Resident Test
Order By RowNumber ASC;

Left Join (Test2)
LOAD
RowNumber, Affirmed, Category,
Peek(RowNumber) as PeekRowNumber,
if(len(trim(Affirmed)) = 0 AND Category = Peek('Category'),
    Peek('Affirmed'), Affirmed) as Affirmed_New,
Peek(Affirmed) as PeekAffirmed
Resident Test Order By RowNumber ASC;

Drop Table Test;

- Marcus

View solution in original post

3 Replies
marcus_sommer

Try it in this way:

Test:
LOAD * INLINE [
RowNumber, Category, Affirmed
1, A, Yes
2, A
3, A, No
4, B
5, B, Yes
6, B, No
7, C
8, C, Yes
9, C, No
10, C
];

// NoConcatenate
Test2:
LOAD
RowNumber //, Category
Resident Test
Order By RowNumber ASC;

Left Join (Test2)
LOAD
RowNumber, Affirmed, Category,
Peek(RowNumber) as PeekRowNumber,
if(len(trim(Affirmed)) = 0 AND Category = Peek('Category'),
    Peek('Affirmed'), Affirmed) as Affirmed_New,
Peek(Affirmed) as PeekAffirmed
Resident Test Order By RowNumber ASC;

Drop Table Test;

- Marcus

bradsiebert
Contributor
Contributor
Author

That worked, thanks!  Is there a rule for when a field inside of Peek needs quotes versus when it does not?

marcus_sommer

Fields in peek() should be always wrapped with single-quotes because it's not a reference to a field within the current load like previous() would do else to a record in a table (which might be also the current one). All functions which query the tables like fieldvalue() or tablename() require strings for the none numeric parameters.

Does it nevertheless worked in some cases it caused from the fact that Qlik interprets them as strings but as far as fieldnames contain a space or any kind special chars it would fail without the quoting.