Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Generate stock for every day

There must be someone who has done this before.

I need to create stock information for ever date, in the script, but I only got the begin amount and the changes.

I think it is easiest to explane with an example.
Here is an example of what I have and want:

I have the changes

Product30-10-201231-10-20121-11-20122-11-20123-11-20124-11-20125-11-20126-11-2012
AAA201-1
33
56
AAB







AAC1003





BBB13-105022045
BBC233

-2
-6
CCC
34

-5
12

This is the result I am looking for:

Product30-10-201231-10-20121-11-20122-11-20123-11-20124-11-20125-11-20126-11-2012
AAA2021202055556066
AAB00000000
AAC100103103103103103103103
BBB14-611232348
BBC2326262624241818
CCC037772214

So for every day I want to have the amount that is in stock based on the changes.

What is the way to do this in the script?

Thanks,

Dennis.

6 Replies
thomas_skariah
Creator III
Creator III

Hi Dennis,

You can try this code in script

If(Date > Previous(Date), RangeSum(Data, Peek('DateNew')), Data) AS DateNew

Regards,

Tom

Anonymous
Not applicable
Author

Thanks Tom , but that doesn't get any results....

Anonymous
Not applicable
Author

I am a bit closer now I think because I have sorted the data in the right way now.

What I got now is data like this:

Product IDdateAmount
AA30-10-20124
AA31-10-2012
AA1-11-2012
AA2-11-20126
AA3-11-2012
AA4-11-2012-3
AA5-11-2012
AA6-11-2012
BB30-10-20121
BB31-10-2012
BB1-11-2012100
BB2-11-2012
BB3-11-2012
BB4-11-2012-25
BB5-11-2012
BB6-11-20123

What I want is:

Product IDdateAmount
AA30-10-20124
AA31-10-20124
AA1-11-20124
AA2-11-201210
AA3-11-201210
AA4-11-20127
AA5-11-20127
AA6-11-20127
BB30-10-20121
BB31-10-20121
BB1-11-2012101
BB2-11-2012101
BB3-11-2012101
BB4-11-201276
BB5-11-201276
BB6-11-201279

Any suggestions?

Thanks,

Dennis.

Gysbert_Wassenaar

You can use peek to calculate the Amount field

LOAD [Product ID],date,

if(rowno()=1,

    Amount,

    if([Product ID] = peek([Product ID]),

        if(len(Amount)=0,

            peek(Amount),

            peek(Amount)+Amount),

        Amount)

    ) as Amount

INLINE [

    Product ID, date, Amount

    AA, 30-10-2012, 4

    AA, 31-10-2012,

    AA, 01-11-2012,

    AA, 02-11-2012, 6

    AA, 03-11-2012,

    AA, 04-11-2012, -3

    AA, 05-11-2012,

    AA, 06-11-2012,

    BB, 30-10-2012, 1

    BB, 31-10-2012,

    BB, 01-11-2012, 100

    BB, 02-11-2012,

    BB, 03-11-2012,

    BB, 04-11-2012, -25

    BB, 05-11-2012,

    BB, 06-11-2012, 3

];


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

I think I got it with Toms solution:

IF(ProductID =Previous(ProductID) , RangeSum(Amount, Peek('Stock') ) , Amount)  as Stock

What do you think?

Anonymous
Not applicable
Author

I am goin to try this too.

Thanks Gysbert.