Conditional calculation is not working