Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
 eddykwan_
		
			eddykwan_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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
 MayilVahanan
		
			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;
 MendyS
		
			MendyS
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		hi 
have you tried to use the function 'peek' - 
Peek - script function ‒ Qlik Sense on Windows
 eddykwan_
		
			eddykwan_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		yes, but I don't know the combination formula.
Can you write example formula for this?
 nenkie
		
			nenkie
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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
		
			MendyS
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		try this -
((currentMonthProduction * Peek('StockField',0,'TableName')) + (current month Sell ))
/
(Peek('productionField',0,'TableName') - current month production)
 
					
				
		
 jmartineze
		
			jmartineze
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi, try with the previous() function.
 eddykwan_
		
			eddykwan_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi Jmartineze,
Can you write the sample combination formula with previous() ?
 
					
				
		
 jmartineze
		
			jmartineze
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		load
....
((currentMonthProduction * Previous( month stock)) + (current month Sell )) / (Previous( month production) - current month production) as NameField
from Table;
 MayilVahanan
		
			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;
 eddykwan_
		
			eddykwan_
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi MendyS,
Thanks for your reply. But its not working for my expectation.
