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

Reference a previous row in table.

Hi Qlik

I am looking at a problem where I have a site that produces 10 units a day and has capacity of 50units. I want to put together a delivery schedule where I'm cumulating the number of units on site that resets once the site reaches 50 eg see table below:

DayQuantity
Monday10
Tuesday20
Wednesday30
Thursday40
Friday50
Saturday10
Sunday20

The formula needs to be something along the line of

IF( Previous days quantity (Q-1) + Increase (P) > Capacity (C),

Q-1 + P -C,

Q-1 +P)

However I don't know how to reference the previous quantity. When culminating values before I have used rangesum(above( but to be entirely honest don't full understand the function.


Any help would be much appreciated.

Kind regards

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Something like this maybe:

LOAD

     Day,

     Quantity,

     If(Quantity+Peek(CumulativeQuantity)> Capacity, Quantity, Quantity+Peek(CumulativeQuantity)) as CumulativeQuantity

FROM

     ....


talk is cheap, supply exceeds demand

View solution in original post

6 Replies
Gysbert_Wassenaar

Something like this maybe:

LOAD

     Day,

     Quantity,

     If(Quantity+Peek(CumulativeQuantity)> Capacity, Quantity, Quantity+Peek(CumulativeQuantity)) as CumulativeQuantity

FROM

     ....


talk is cheap, supply exceeds demand
Not applicable
Author

Hi Gysbert,
Thanks for getting back so quickly.

The capacity and quantity are being drawn from two separate data loads, will this be an issue?

sunny_talwar

Some useful links to look at for script options

Peek() vs Previous() – When to Use Each

Peek() or Previous() ?

For front end chart objects, you can check this link out

Missing Manual - Above() and Below()

vinieme12
Champion III
Champion III

can you post a sample of your desired output

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Gysbert_Wassenaar

Not if you first join them into one table. Otherwise yes. A load can only reference fields from its only source table.


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert