function to calculate subtotal