You might want to look at Level of Detail calculations, which can create a calculation that operates relative to a specified field. See these resources for some introductory knowledge on LoDs:
Also, it would be really helpful to publish a workbook here, if you can. Calculations are hard to explain without knowing the exact set up.
Hope that helps! Good luck.