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.
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 ...