I have no such file but you can find lots of examples. One issue for me is that it's not clear where your head is at with respect to storing this calculation in the first place. Sounds like you are bent on calculating the qoh and storing that though, and that I won't help with. Reason being, it's not something I'd do and if I proffer a method and you need to tweak it later, I don't want to feel obligated to help you fix my idea when you shouldn't be doing it anyway.

If you get stuck in your research, a pic of your relationships window (if you've established them) might shed some light.