Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

peek function is not working if we have only one record

Hi

I have scenario,

I have one record per location.I need to calucalate growth i.e. Sales-Prev_sales

But when i use Peek function in script it is not working properly it is showing different values.

Expected is Prev_sales is 0 and Growth is Sames as Slaes.

Please so the needful for Peek what extra steps i need to configure in this case.

Thanks

Thiru

1 Solution

Accepted Solutions
tresesco
MVP
MVP

First you have to control the Sort Order of the load when checking the last value using peek(). Then make sure you check to check if the last record is from same Region and Location. Try like:

Load   ....

     If( Region=Peek(Region) and Location=Peek(Location),Peek(Sales),0) as Prev_Sales

    resident Directory1 Order by Region, Location, Date;


PFA


View solution in original post

5 Replies
MK_QSL
MVP
MVP

What is the output you are looking for?

tresesco
MVP
MVP

First you have to control the Sort Order of the load when checking the last value using peek(). Then make sure you check to check if the last record is from same Region and Location. Try like:

Load   ....

     If( Region=Peek(Region) and Location=Peek(Location),Peek(Sales),0) as Prev_Sales

    resident Directory1 Order by Region, Location, Date;


PFA


Anil_Babu_Samineni

What are you trying to do for this Prev_Sales? Would you describe more

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

Hi Anil,

I am looking for

 

LocationDateSalesPrev_salesGrowth
2522    0762
Bangalore01-11-2017562   0562
Chennai01-11-2017560     0560
Delhi01-11-201789      089
Hyderabad01-11-2017460    0460
Pune01-11-2017851      0851

Thanks

Thiru

Anil_Babu_Samineni

Then Look Tresesco Suggestion and let us know

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful