Check attached qvw. Your calculated figure is wrong, it should be something like: 0.2054...
stocktest_tres.qvw 171.8 K
It is not working properly as per the requirement. Сергей Покасов's solution is working properly as per my previous requirement but I am posting the updated logic with attached application.
For any RecID,ITEM,Warehouse,Color, DimID combination if last row have QTY_StockIn value with >0 then that row will be considered otherwise any other previous row on behalf of the last row where the QTY_StockIn value is >0 then that QTY_StockIn value and its corresponding AMT_StockIn value should be considered to calculate the m_AMT_StockCL. And also apply the logic using RecordId because it is unique.Do not depend on the date as it cant be in a sorted manner but recordid corresponding to that date will always be unique.
Ex:- On belhalf of the attached Application,
as per the example
Inventory Closing Qty:1200
Here on the last record,
QTY_StockIn = -1350
but we have to find in which last entry QTY_StockIn is >0,
So on the previous record, QTY_StockIn is 1350 then that record will be considered, but for that case we find >0 value for QTY_StockIN on last previous record and it is not static for all cases we can find anywhere the last >0 value QTY_StockIn, If Last record value have QTY_StockIn >0 then that record should be considered for taking IN QTY and Amount.
So The m_AMT_StockCL=
*1200(Inventory Closing Qty) =95299.14
I think implementing that logic inside script will be a great thing. Please check and if find any solution then share here.