Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Previous row in script

Hi All,

I need have date ,product,region and district as fields in my script.

Now i need to get the previous volume for each date based on product.How can i achieve that??

Kindly help.

Regards,

Reena

15 Replies
tamilarasu
Champion
Champion

Hi Reenaabraham,

Try Peek() or Previous function.

tresesco
MVP
MVP

Check this post: Peek() or Previous() ?

Not applicable
Author

I tried it.but it is coming based on the date.i need to get it based on both product basis and also by date wise.

Kushal_Chawda

Provide some sample data with expected output to get the exact solution

parevrac
Contributor III
Contributor III

you need to use Peek('fieldname', RecNo()-1,'table')  BUT you must sort the input table first in the order you need it so that the previous row always contains the values you want to compare.

simospa
Partner - Specialist
Partner - Specialist

Hi,

use Peek() or Previous() as indicated by the other users, use it ordering the data in the order you wish

For example somthing like this

LOAD product,region, district, date, volume, peek(volume) as previous_volume

FROM yoursource

ORDER BY product asc, date asc

Eventually use a GROUP BY too, it depends from your data.

S.

Not applicable
Author

Hi All,

Attaching the sample data for your reference.

sunny_talwar

You seem to have multiple products on a single date. What exactly is your expected output from the same you have provided?

Not applicable
Author

Hi i need to get the previous date value for each product.

Date       Product  Volume     Output

01-01-15  ABC   100             0

01-01-15  BCA   200             0

01-01-15  ACB   400             0

02-01-15  ABC   250             100

02-01-15  BCA    50              200

02-01-15  ACB   150             400  

02-01-15  HIJ     150             0