Can you post your existing code here and mention where you want this formula to be inserted?

It will be much easier to help you if we see the whole code.