Calculate Weighted Average Cost of Inventory

How can I calculate the Weighted Average Cost of inventory in an Inventory Transactions table.
Here is the link to a sample of the inventory transactions. The average cost needs to be update every time there is a new Inventory Receipt.

Sample transactions table

Theoretically the formula is

(Balance of Inventory before new Receipt * Old Average Cost) + (No of items now received * Unit Cost of Items Received) / Total Number of Units now in stock.