I recently wrote a report for a customer with Average costing switched ON, so there were no dated lots/batches to use in the aging.
I made the assumption that FIFO was used.
I first calculated the receipts (POs, Jobs, Adjustments and Stock Receipts) quantities and values for the last 3, 6, 9, 12 (etc.) months, at Actual Costs (from InvMovements).
I then systematically calculated backward from the InvWarehouse.QtyOnHand, by deducting each period’s receipts, until InvWarehouse.QtyOnHand was ‘depleted’. The remaining periods’ receipts were then cleared/zeroed.
Let me know if you need assistance with something similar.