Select to view content in your preferred language

Cost breakdown form with relevant fields. Sum fails because relevant defaults Null

349
2
Jump to solution
11-02-2023 05:20 AM
Cyprus_Forest_Department
Occasional Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

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. 

- Jen

View solution in original post

0 Kudos
2 Replies
JenniferAcunto
Esri Regular Contributor

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. 

- Jen
0 Kudos
Cyprus_Forest_Department
Occasional Contributor

Thank you so much, that worked perfectly!

0 Kudos