Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Bloody newbie question - PEEK vs. PREVIOUS?

Hi,

I have worked with both of these functions before - afaIk, if you use PEEK() without another parameter (save the fieldname in quotes), that should look up the last read record according to the sorting. You can use it in the same LOAD where you actually do the necessary sorting, can't you?

Well, PREVIOUS afaIk does exactly the same, no? You cannot do different things with that, it always just looks up the previous record, the one that was loaded just previously.

<=> Well, apparently this is not so.

I have a block of script where customer data is sorted by several criteria, including the month - there is one record per month (per the other criteria), so after this sorting, the order should be like >> 201701 -> 201702 <<.

In the original data, there are YTD values. The logic is, after this sorting if all the criteria save the month are identical to the record last loaded, then the records should be sorted by month, so one YTD_value minus the previous YTD_value should return that specific month's value.

For some reason, this works with PEEK() - with PREVIOUS() it seemingly does not.

Can you tell me what exactly is the difference?

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
3 Replies
datanibbler
Champion
Champion
Author

Ah, I see - the difference is that PREVIOUS uses the data_source, not the in-memory database built by QlikView.

So what if this is done in a RESIDENT LOAD? Then PREVIOUS() would use the first table where there is no sorting yet, no? Well, that would be it ...

I would be grateful if someone could confirm that.

marcus_sommer

Here it's very well explained: Peek() or Previous() ?

- Marcus

datanibbler
Champion
Champion
Author

Thanks Marcus!

That confirms my suspicion: The PREVIOUS() function would in this case use the first table I have loaded which was not yet sorted in the correct order, so it would not look up the last record AFTER sorting, but BEFORE, which is of course wrong because my calculation requires sorting.

I could maybe use it if I was to put another RESIDENT LOAD inbetween where I do the sorting, but why load it all one more time save for the safety that if something is misspelled, PREVIOUS() will throw an error while PEEK() won't ...