Item ledger average cost History

I’m looking for a simple way to implement three more fields in the item ledger entry, total quantity, total value, and average cost. These fields should display the values in the location for that item due to that entry. I’ve been trying to do this with flow fields and flow filters but all the records display the values for the last ledger entry since the CalcFormula of these special fields doesn’t allow < or > comparisons. Anyone knows how to solve this issue? Thank you very much Paulo