Maybe this post will give you an idea of how to do it. Make a copy of it and look at the formulas I used.