Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
tomhovens
Contributor II
Contributor II

Average inventory

Dear qlikviewer,

How to calculate the average inventory in qlikview. please the table

ItemnrDateSerialnrWarehousenrMutationInventoryOldInventoryNew
11-12-201401-51510
115-11-20141121315
115-11-201402-220
110-11-20140110313
11-11-201412202
11-11-201401303

Extra info: there are a lot of itemnr

Who could help me?

18 Replies
Gysbert_Wassenaar

rangesum(Firstsortedvalue(InventoryOld, Date),Firstsortedvalue(InventoryNew,-Date))/2


talk is cheap, supply exceeds demand
anbu1984
Master III
Master III

Do you want to calculate average of inventory for each itemnr monthly or weekly or entire input?

Itemnr, Avg(InventoryNew)

1,43/6

tomhovens
Contributor II
Contributor II
Author

What do you mean with Firstsortedvalue

ThornOfCrowns
Specialist II
Specialist II

From HELP (F1)

firstsortedvalue( [{set_expression}][ distinct ] [ total [<fld {, fld}>]] expression [, sort_weight [, n]])

returns the first value of expression sorted by corresponding sort-weight when expression is iterated over the chart dimension(s). Sort-weight should return a numeric value where the lowest value will render the corresponding value of expression to be sorted first. By preceding the sort-value expression with a minus sign, the function will return the last value instead. If more than one value of expression share the same lowest sort-order, the function will return null. By stating an n larger than 1, you will get the nth value in order.

Examples:
firstsortedvalue ( PurchasedArticle, OrderDate )     

firstsortedvalue ( PurchasedArticle, -OrderDate, 2 )     

firstsortedvalue ( A/B, X*Y/3 )    

firstsortedvalue ( distinct PurchasedArticle, OrderDate )     

firstsortedvalue ( total PurchasedArticle, OrderDate )    

firstsortedvalue ( total <Grp> PurchasedArticle, OrderDate )   

MarcoWedel

can you specify the calculation of the average inventory for your sample data?

tomhovens
Contributor II
Contributor II
Author

I attached the Qlikviewfile.

The correct answer Qlikview has to calculate is

ItemnrDateSerialnrWarehousenrMutationInventoryOldInventoryNewColumnXColumnY
11-12-201401-5151016240
115-11-20141121315565
115-11-201402-2201428
110-11-20140110313927
11-11-20141220200
11-11-20140130300

Column X: DateRow - DateRowPrevious WHERE warehousenr is equal

Column Y: Column X * InventoryOld

jagannalla
Partner - Specialist III
Partner - Specialist III

Hi,

Can you explain little bit more on Column X calculation. At least for two or three rows.

Thanks,

Jagan

tomhovens
Contributor II
Contributor II
Author

Sure,

Column X is like match and index

I look for the next rows when itemnr is equal and warehousenr is equal

ItemnrDateSerialnrWarehousenrMutationInventoryOldInventoryNewColumnXColumnY
11-12-201401-5151016 (1-12-2014 - 15-11-2014)240
115-11-201411213155 (15-11-2014 - 10-11-2014)65
115-11-201402-22014 (15-11-2014 - 1-11-2014)28
110-11-201401103139 (10-11-2014 - 1-11-2014)27
11-11-20141220200
11-11-20140130300
jagannalla
Partner - Specialist III
Partner - Specialist III

That's fine. But how are you getting the values 16,5,14,9. According to you 16(from inventorynew 10-15 is -5). We need the information from which columns you are getting the values.