Hallo.
I have a form for breaking down the cost for treating monument trees.
The user chooses from a select multiple question one or many causes for treatment (${TreatmentType}).
Then the respective question pops up so as to populate the individual cost via a relevant expression (${TreatmentCostA} or/and ${TreatmentCostB}).
However, the total cost field (${TotalCost}) gets Null, when it has a calculation expresion to add the two fields (${TreatmentCostA} + ${TreatmentCostB}).
Found a post that inscribes to set the default values of ${TreatmentCostA} and ${TreatmentCostB} as 0 and then the ${TotalCost} indeed has the sum calculated, however leaving the ${TreatmentType} field potential empty.
Tried even to set a constrain for the ${TreatmentType} field number(${TotalCost}) > 0 so as to prompt the user to go back and select the respective treatment that he populated the cost bellow but didn't manage to make it work.
Any ideas? Thank you guys for the help.
Solved! Go to Solution.
Remove the 0 defaults for your Treatment Costs fields and incorporate some if statements into your TotalCost calculation to account for the possible null values.
if(selected(${TreatmentType}, 'A'), ${TreatmentCostA}, 0) + if(selected(${TreatmentType}, 'B'), ${TreatmentCostB}, 0) + if(selected(${TreatmentType}, 'C'), ${TreatmentCostC}, 0)
Basically, that calculation is saying if TreamentType A is selected, add that value, if not, add 0 instead. Repeated for Types B and C.
Remove the 0 defaults for your Treatment Costs fields and incorporate some if statements into your TotalCost calculation to account for the possible null values.
if(selected(${TreatmentType}, 'A'), ${TreatmentCostA}, 0) + if(selected(${TreatmentType}, 'B'), ${TreatmentCostB}, 0) + if(selected(${TreatmentType}, 'C'), ${TreatmentCostC}, 0)
Basically, that calculation is saying if TreamentType A is selected, add that value, if not, add 0 instead. Repeated for Types B and C.
Thank you so much, that worked perfectly!