Announcements
cancel
Showing results for
Did you mean:
Partner - Contributor III

## How to get the stock value from previous row

Hi Everyone,

Now I want to calculate the stock for all the months and the formula is :

((currentMonthProduction * Previous month stock) + (current month Sell )) / (Previous month production - current month production)

Let me give an example of how the data is

Thank you

Labels (10)

• ### Visualization

1 Solution

Accepted Solutions
MVP

Hi

Based on my understanding, for 1st row, its Production - Sell to get the Stocks. If so, try like below

If(Rowno() =1, Production - Sell, ((Production * Peek('StockField')) + (Sell))

/

(Peek('Production') - Production)) as StockField

resident ursource

order by Month;

Thanks & Regards, Mayil Vahanan R
10 Replies
Partner - Creator III

hi
have you tried to use the function 'peek' -
Peek - script function ‒ Qlik Sense on Windows

Partner - Contributor III
Author

yes, but I don't know the combination formula.

Can you write example formula for this?

Contributor

Fears of a potential economic slowdown are clouding the outlook for value stocks, which have outperformed broader indexes this year in the ...Hyperfund Login

Partner - Creator III

try this -

((currentMonthProduction * Peek('StockField',0,'TableName')) + (current month Sell ))

/

(Peek('productionField',0,'TableName') - current month production)

Partner - Creator

Hi, try with the previous() function.

Partner - Contributor III
Author

Hi Jmartineze,

Can you write the sample combination formula with previous() ?

Partner - Creator

....

((currentMonthProduction * Previous( month stock)) + (current month Sell )) / (Previous( month production) - current month production) as NameField

from Table;

MVP

Hi

Based on my understanding, for 1st row, its Production - Sell to get the Stocks. If so, try like below

If(Rowno() =1, Production - Sell, ((Production * Peek('StockField')) + (Sell))

/

(Peek('Production') - Production)) as StockField

resident ursource

order by Month;

Thanks & Regards, Mayil Vahanan R