A basic method that you can find in many "transactions" type tables:
Define a calculation field that combines the "in" and "out" values:
I'll call it cBal and write the calculation like this:
Returned - Dispensed
define a running balance summary field to compute the "total of" cBal. (You can set this to restart the total with each different material.)
An opening balance can be created by entering that amount in the returned field for the first transaction for a given material.
There are also scripted approaches that can, each time you add, modify or delete a transaction, updates the total on hand value via a script that puts this value into a number field for better performance. This can make a difference as the total number of transactions increase over time unless you periodically "condense" them by replacing the older transactions with a new balance forward entry.