I'm wondering if I can use an "if" statement in my survey to create a conditional calculation for a Total Cost field (integer) who's calculation is dependent on {epm} = Yes versus when {epm} = No.
The condition would be something like:
if(${epm}, 'yes') then total_cost = ${epm_cost}+ ${repair_cost}
if(${epm}, 'no') then total_cost = ${repair_cost}
The kicker is that {epm} is only relevent when cat_a, cat_c, or cat_d (and so forth) are selected.
When Cat_B is selected, {epm} cannot be relevant
I've set the default of {epm_cost}, {repair_cost}, and {total_cost} to 0 so that the calculate is run regardless of an actual cost being entered. However, when {epm} is 'no', {epm} is not relevant and therefore not included into the {total_cost} calculation creating a Null {total_cost}.
I've attached a copy of the specific lines from my survey as well.
Thoughts???
I am not sure why your relevant on line 3 is not the opposite like != '' should work. That Or sting-length() > 0 will tell you when something is still empty. Having all those or statements with the value is slower.
For epm just add a second hidden field. You can do the same string-length trick above or just use epm ='yes' again (no need to use selected just = is fine).
So if(${epm}='yes',${epm_cost},0) then use this hidden field in your calc.
Hope that helps.
Thank you Doug! This works for what I'm needing, with the one exception that my total_cost is concatenating the new hidden field instead of adding it to the total as a sum. I believe this is a separate issue as I have verified my bind::esri:fieldType is set to esriFieldTypeInteger. I have also created a new identical survey to first publish with the new hidden field as an integer and then republish as hidden and esriFieldTypeInteger and it's still concatenating. My total_cost calc is coalesce(${epm_cost},0)+coalesce(${repair_cost},0)+coalesce(${epm_cost_b},0) where epm_cost_b is the new hidden field.
You need to set bind::type one to int instead. Or use number().
Ah thank you! I hadn't even realized I was using an old survey form that did not have the bind::type column.. All good now.