Skip to main content

# New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
Skip the ticket, Chat with Qlik Support instead for instant assistance.
cancel
Showing results for
Search instead for
Did you mean:
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

Please help me to write this script?

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

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.
10 Replies
Creator II

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

Creator II

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

load

....

((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

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.
Partner - Contributor III
Author

Hi MendyS,

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

Tags
Community Browser