Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Calc Avg Cost for an Item from Item Trans table

Status
Not open for further replies.

awaria

IS-IT--Management
Sep 16, 2010
100
0
0
US
Appreciate some guidance.

Apologize in advance, not a programmer, but, tasked with providing this data.
Can perform std joins and less complicated queries.

Not sure how to store or perform running total. Not sure of best method for gathering this data.

Thanks in advance for your input, awaria
--

Goal: Calc avg cost for item;

Tables: Item Master and Item Transaction

Item Master has field QtyonHand = 10 for item A

Item QOH
A 10

Item Trans most recent transactions;

Item Qty Cost Date
A 4 10.00 2/28/18
A 4 20.00 2/17/18
A 4 30.00 2/16/18

How to loop through trans table for most recent transactions, selecting the
cost for the 4 from 2/28/18, the cost for 4 from 2/27/18 and then cost for
just 2 out of 4 from 2/26/18 to arrive at an avg cost of $18.00 for the Item Master table's QOH of 10?
 
select (sum (item*qty)) / sum(qty) from ItemTransaction where item = 'A')

Not clear to me how Quantity on Hand affects anything you've asked for. Also, your example looks wrong as they dates seem to be off.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top