calculate total value for each category in a given list