This is quite complex and I don't know if you can do it. sounds like you need a calculus addin

Matt