Calculations within Custom Field from Custom Item Field (Showing Item Category with Subtotal)

Calculations within Custom Field from Custom Item Field (Showing Item Category with Subtotal)

I am trying to do some template customisations and show a subtotal amount for all items 'from a category'

1)
I have added a Dropdown custom category field within items
API Name is now cf_category

2) 
I added a drop down custom field with

Category Name 1
API Name = cf_subtotal_of_category_name_1

Category Name 2
API Name = cf_subtotal_of_category_name_2

Category Name 3
API Name = cf_subtotal_of_category_name_3

3)
Within my Estimate Template I can show this Category Name by using the placeholder

${ESTIMATE.Item.CF.Category.Value}

4)
I created new subtotal fields for my category names which go into my template with placeholders between the 

standard ones..

%EstimateSubTotal%

${estimate.cf_subtotal_of_category_name_1}
${estimate.cf_subtotal_of_category_name_2}
${estimate.cf_subtotal_of_category_name_3}

%EstimateTotal%

Can someone please help me with the script to automate this and run calculations  ;

Add up all item amounts for Category Name 1 and show that value in
${estimate.cf_subtotal_of_category_name_1}

Add up all item amounts for Category Name 2 and show that value in  ${estimate.cf_subtotal_of_category_name_2}

Add up all item amounts for Category Name 3 and show that value in  ${estimate.cf_subtotal_of_category_name_3}


I hope this makes sense.
Thank you.