Conditional calculation based on quantity