modify code to calculate sum for only the active tab