select_one questions, count each response

821
3
Jump to solution
02-11-2020 02:45 PM
IvanKozoletov1
New Contributor III

With some help from Ismael I designed this form for our Annual Playgrounds inspections workflow. It works exactly as planned and I'm now moving onto the Monthly/Weekly inspection forms.  Select_one type of response for the Annual inspection is:

Satisfactory = 1

Unsatisfactory = 0

Where for Monthly/Weekly forms we got N/A answer added to the mix:

Satisfactory = 1

Unsatisfactory = 0

N/A = ?

This is where I'm struggling. What is the best value to assign to N/A variable, can I mix & match strings and integers in the same field or N/A has to be a number as well? If I assign -1 to N/A answers how can I make sure to get the accurate counts of each question in the end regardless of the response?

0 Kudos
1 Solution

Accepted Solutions
Jim-Moore
Esri Regular Contributor

Hi Ivan

By default the select_one question type uses a text field so "0", "1" and "N/A" could all be stored (as strings) in the same field. The int() function in your calculation casts the "0" and "1" strings as integers so they can be treated as numbers and summed.

One suggested approach would be to use IF statements in your count calculation to evaluate each question and make it 1 or 0 accordingly. For example:

if(selected(${Equip_Stabil1},'1'),1,0) + if(selected(${Fill_Dishing2},'1'),1,0) + if(selected ... etc.

Then write a similar calculation for the unsatisfactory and not applicable cases. In this scenario, your choice list need not use digits as values; depending on how you would like to store these values in the feature service, you could use more descriptive strings, i.e. "satisfactory", "unsatisfactory" and "not_applicable" in the name column. Then your calculation would look something like:

if(selected(${Equip_Stabil1},'satisfactory'),1,0) + if(selected(${Fill_Dishing2},'satisfactory'),1,0) + if(selected ... etc.

Hope this helps.

Best,

Jim

View solution in original post

3 Replies
Jim-Moore
Esri Regular Contributor

Hi Ivan

By default the select_one question type uses a text field so "0", "1" and "N/A" could all be stored (as strings) in the same field. The int() function in your calculation casts the "0" and "1" strings as integers so they can be treated as numbers and summed.

One suggested approach would be to use IF statements in your count calculation to evaluate each question and make it 1 or 0 accordingly. For example:

if(selected(${Equip_Stabil1},'1'),1,0) + if(selected(${Fill_Dishing2},'1'),1,0) + if(selected ... etc.

Then write a similar calculation for the unsatisfactory and not applicable cases. In this scenario, your choice list need not use digits as values; depending on how you would like to store these values in the feature service, you could use more descriptive strings, i.e. "satisfactory", "unsatisfactory" and "not_applicable" in the name column. Then your calculation would look something like:

if(selected(${Equip_Stabil1},'satisfactory'),1,0) + if(selected(${Fill_Dishing2},'satisfactory'),1,0) + if(selected ... etc.

Hope this helps.

Best,

Jim

IvanKozoletov1
New Contributor III

Jim,

I cannot thank you enough for this elegant solution that you offered! I was unaware of selected() function and how to use it. This works great and I went with the spelled out choices (satisfactory/unsatisfactory/NA) so they are meaningful in the feature service. This is the best way getting counts regardless of the answer type. Thank you.

Jim-Moore
Esri Regular Contributor

Great to hear it's working well Ivan! In case you haven't seen it, there's plenty of handy info regarding operators, functions, etc. in this quick reference.

Quick reference—Survey123 for ArcGIS | Documentation 

Also some great tips for multiple choice questions in this blog: https://community.esri.com/groups/survey123/blog/2018/12/02/survey123-tricks-of-the-trade-xlsform-fu... 

Best,

Jim

0 Kudos