Tally "Select-One" answers in a repeat?

949
4
Jump to solution
05-13-2019 09:20 AM
deleted-user-a_zHTK67PWYA
New Contributor II

Is it possible to have Survey123 tally selected answers in a repeat? The repeat "select one" question has five answers to choose from. I need to calculate the number of times each answer is selected for some calculations later in the survey outside of the repeat.

1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Calene,

Yes, looks like you are almost there. The problem is that the select one is a text question type, so when you use it in a calculation, such as in your hidden questions, the result ends up being a text answer. Therefore you need to case the calculations as integer, and also you can try setting the bind:type column to int also.

You calc for example would look as follows: int(if(selected(${useclass},'8'),1,0)). If that doesn't work you may need to put the int() inside the if statement. Also you may need to do the same on the summary calculations.

If you are still having trouble getting it to work properly, can you send your xlsx file and I can take a closer look.

Phil.

View solution in original post

4 Replies
by Anonymous User
Not applicable

Hi Calene,

Yes this should be possible using a few extra fields in your repeat, to do a selected and provide a value of 0 or 1 if the value are are wanting to count is selected. You would need 5 extra fields in the repeat to do this, or use on field but different values that you can tally separately in later calculation. You can make these extra fields hidden or null to avoid them being displayed on form or saved to feature service. Depends on your use case and need to store data.

You can then use the aggregate function of sum() outside of the repeat in a calculation, to sum those additional fields for each one that matches and get a tally of the repeats for those select one questions.

Hope this helps,

Phil.

deleted-user-a_zHTK67PWYA
New Contributor II

I am almost there with solving this issue but the syntax I'm using doesn't return an integer I can use in calculations. Instead its returning a string of text. What syntax should I use in the calculation column for my five hidden rows within the repeat. Please see inserted screen shots:

0 Kudos
by Anonymous User
Not applicable

Hi Calene,

Yes, looks like you are almost there. The problem is that the select one is a text question type, so when you use it in a calculation, such as in your hidden questions, the result ends up being a text answer. Therefore you need to case the calculations as integer, and also you can try setting the bind:type column to int also.

You calc for example would look as follows: int(if(selected(${useclass},'8'),1,0)). If that doesn't work you may need to put the int() inside the if statement. Also you may need to do the same on the summary calculations.

If you are still having trouble getting it to work properly, can you send your xlsx file and I can take a closer look.

Phil.

deleted-user-a_zHTK67PWYA
New Contributor II

Phil,

int() didn't do it but bind:type int did! Thanks a bunch!

Calene