I'm trying to build a survey where users can select if a habitat site is suitable, marginal, or unsuitable for a given species for a group of three questions. At the end of this group, I want to calculate which category the site falls in, based on whether suitable (S), marginal (M), or unsuitable (U) was selected the most. If all three were selected (SMU), marginal should be the final determination. E.g. SSM=S, MUM=M, UMS=M, etc.
I have tried assigning numeric values to the three responses, so I could create distinct numeric ranges that would result in a given final answer. For example, S=20, M=2, U=0, so SSU would = 40. However, I cannot find the right numeric values that result in distinct ranges to build the calculation from.
Is it possible to do a calculation with letters instead of numbers, or do I need to build a long if, then statement to calculate my answer? I imagine that this would look something like if(${question1}='s' and ${question2}='u' and ${question3}='s', 's', 'na').
Any advice on the best way to approach this would be greatly appreciated!
Solved! Go to Solution.
Probably a few ways to do this, but here's one that's pretty straightforward.
Have your three question fields use S / M / U text values.
Have three hidden integer questions in your form - s_count, m_count, u_count. These need to have the bind::esriFieldType values set to null, don't want these going to your data. Each one will have a calculation on them:
int(if(${q1} = ‘S’, 1, 0)) + int(if(${q2} = ‘S’, 1, 0)) + int(if(${q3} = ‘S’, 1, 0))
(The m_count question and u_count question would be the same, but with 'S' changed to the appropriate letters.)
Finally, you'd have a result field with a calculation like this:
if(${s_count} >= 2, ‘S’, if(${m_count} >= 2, ‘M’, if(${u_count} >= 2, ‘U’, ‘M’)))
This will check if any of the counts are greater than or equal to 2, and if not, fall back to M.
Probably a few ways to do this, but here's one that's pretty straightforward.
Have your three question fields use S / M / U text values.
Have three hidden integer questions in your form - s_count, m_count, u_count. These need to have the bind::esriFieldType values set to null, don't want these going to your data. Each one will have a calculation on them:
int(if(${q1} = ‘S’, 1, 0)) + int(if(${q2} = ‘S’, 1, 0)) + int(if(${q3} = ‘S’, 1, 0))
(The m_count question and u_count question would be the same, but with 'S' changed to the appropriate letters.)
Finally, you'd have a result field with a calculation like this:
if(${s_count} >= 2, ‘S’, if(${m_count} >= 2, ‘M’, if(${u_count} >= 2, ‘U’, ‘M’)))
This will check if any of the counts are greater than or equal to 2, and if not, fall back to M.
That worked perfectly, thank you so much!