How can I create a conditional for a sum?