Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
eddykwan_
Partner - Contributor III
Partner - Contributor III

How to get the stock value from previous row

Hi Everyone,

Please help me to find the formula script based on previous row.

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

eddykwan__0-1658130982450.png

 

Please help me to write this script?

Thank you

1 Solution

Accepted Solutions
MayilVahanan

Hi

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

Load *,

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

/

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

resident ursource

order by Month;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

10 Replies
MendyS
Partner - Creator III
Partner - Creator III

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

eddykwan_
Partner - Contributor III
Partner - Contributor III
Author

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

Can you write example formula for this?

nenkie
Contributor
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 

MendyS
Partner - Creator III
Partner - Creator III

try this - 

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

/

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

jmartineze
Partner - Creator
Partner - Creator

Hi, try with the previous() function.

eddykwan_
Partner - Contributor III
Partner - Contributor III
Author

Hi Jmartineze,

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

 

jmartineze
Partner - Creator
Partner - Creator

load

....

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

from Table;

MayilVahanan

Hi

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

Load *,

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

/

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

resident ursource

order by Month;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
eddykwan_
Partner - Contributor III
Partner - Contributor III
Author

Hi MendyS,

Thanks for your reply. But its not working for my expectation.