I have a supply inventory data table that includes Item Description, Date of Inventory, and Inventory Quantity.
It keeps a running history of inventory of inventory quantities and the date. It is a child table to the Supply table so there can be many records for each supply. Not all supplies get inventories at the same time because it takes several days to complete an inventory and some supplies are inventoried less frequently than others.
I want to be able to see the rate at which supplies are being depleted, so I want to query in such a way to take the most recent quantity, subtract it from the second most recent quantity, and then divide that by the difference in days between the two associated dates.
Since the dates vary from item to item I can't figure out how tell it that I want to use the two most recent records.
So let's say the table looks like this:
Item Desc. Inventory Date Quantity
Widget A ...... 3/1/14 ....... 700
Widget A ...... 4/3/14 ....... 380
Widget A ...... 4/30/14 ...... 210
Widget B ...... 3/6/14 ........ 43
Widget B ...... 5/15/14 ....... 21
Widget C ...... 4/7/14 ...... 1200
Widget C ...... 4/15/14 ...... 980
Widget C ...... 5/1/15 ....... 700
I would want the query to calculate:
Widget A (380-210)/(4/30/14 - 4/3/14)
Widget B (43-21)/(5/15/14 - 3/6/14)
Widget C (980-700)/(5/1/14 - 4/15/14)
(The results are average daily depletion rates)
Is this possible?
Thanks.
It keeps a running history of inventory of inventory quantities and the date. It is a child table to the Supply table so there can be many records for each supply. Not all supplies get inventories at the same time because it takes several days to complete an inventory and some supplies are inventoried less frequently than others.
I want to be able to see the rate at which supplies are being depleted, so I want to query in such a way to take the most recent quantity, subtract it from the second most recent quantity, and then divide that by the difference in days between the two associated dates.
Since the dates vary from item to item I can't figure out how tell it that I want to use the two most recent records.
So let's say the table looks like this:
Item Desc. Inventory Date Quantity
Widget A ...... 3/1/14 ....... 700
Widget A ...... 4/3/14 ....... 380
Widget A ...... 4/30/14 ...... 210
Widget B ...... 3/6/14 ........ 43
Widget B ...... 5/15/14 ....... 21
Widget C ...... 4/7/14 ...... 1200
Widget C ...... 4/15/14 ...... 980
Widget C ...... 5/1/15 ....... 700
I would want the query to calculate:
Widget A (380-210)/(4/30/14 - 4/3/14)
Widget B (43-21)/(5/15/14 - 3/6/14)
Widget C (980-700)/(5/1/14 - 4/15/14)
(The results are average daily depletion rates)
Is this possible?
Thanks.