Calculation condition not working properly