Count number of filtered alternatives in a single select

Hello,

Can I count the number of available alternatives in a single select question after filtering? Note that my single select question binds to a previous list question.

I want to do this to add an enabling condition. I only want to show this question if there is at least one alternative available in the filtered list.

Thank you!
Maria

??? So what is the filter like?

Here is the actual filter of question r1 (Who will respond in lieu of %name1%?), where numHW is a numeric question and i# are long integer functions:

@optioncode != i1
&& @optioncode != ((numHW>=2)? i2:-2)
&& @optioncode != ((numHW>=3)? i3:-3)
&& @optioncode != ((numHW>=4)? i4:-4)
&& @optioncode != ((numHW>=5)? i5:-5)
&& @optioncode != ((numHW>=6)? i6:-6)
&& @optioncode != ((numHW>=7)? i7:-7)
&& @optioncode != ((numHW>=8)? i8:-8)

This is a link to the questionnaire RND_8:

https://designer.mysurvey.solutions/questionnaire/details/d2218680ca054ba1b15c4cf9743a474f/chapter/fed2d39c449b02a93fa3b287895e021b/group/fed2d39c449b02a93fa3b287895e021b#shareTab

I wish I knew what information is relevant to answer my question, but I don’t.

Thank you, Maria

Maria, this kind of check leaves a possibility for a rather strange situation where in a group of Alice and Bob, Alice can’t answer for Bob. Which is rather strange, but is up to your project of which you give no details.

Thus it is best to start formulating your check in plain [English] language, as if you are conducting a training of the enumerators and you are explaining them what is being checked. This will either make a contradiction apparent, or confirm that such behavior is desired.

The number of alternatives is probably this expression:

list.Count(x->x.Item1!=i1 && x.Item1!=i2 && ...)

I don’t have an idea of why you have a ternary operator there, or what those -2, -3, etc mean.

Hope this helps.

Works perfectly! Thank you so much.

All your conclusions about my confusing message are correct:

This is a situation where Alice and Bob are randomly selected from a list. If Alice can’t answer, Bob cannot answer for her, because he has also been selected to answer. The “replacement” for Alice needs to be someone else from the list, if there is someone left in the list.

Those -2, -3, etc mean that non-programmers do not know how to program, but instead find working solutions. They sit in for the condition “else, do nothing”. I know… It’s ok, it works for me.

I’ll get better :wink:

Thank you again, Maria

The “replacement” for Alice needs to be someone else from the list, if there is someone left in the list.

In the current logic the questionnaire will ask : “Is Alice responding for herself?” And then when the interviewer enters NO as an answer, no further question will be asked on the proxy respondent, since by your desired behavior the question will be suppressed because there are no alternatives. So the interviewer will not feel anything is wrong unless you tell him/her. Consider introducing an error message “Alice must respond for herself!” in such a case, though it is hardly enforceable.

Depends of course on the number of sampled respondents, e.g. if it is always less than a half of the group - there will always be an alternative.

It was also not 100% clear for me whether one respondent may proxy for several selected. It seems that you are only checking that they don’t answer one selected for another selected. But can e.g. Charlie answer for both Alice and Bob?

On the ternary operator: it would make sense to introduce -999 as a code of an ‘impossible person’, but I couldn’t get why the variation (-2, -3) ?

If you are trying to protect against missing values (nulls) consider using the ??-operator.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator
which is probably redundant here, but is indispensable in some other situations.

Best, Sergiy

Thank you for this message, it helps me a lot.

Any guidance on how to avoid Charlie to answer for both Alice and Bob? I tried for a few hours, but I get “Circular references are not allowed”, which makes total sense. My plan was to pass this check onto enumerators and supervisors.

You are right, I will create a warning of the kind “ Alice must respond for herself! ”. I guess I will ask the supervisor to be called-in to verify that Alice is truly out reach, with the possibility to schedule a second visit or some cumbersome protocol that discourages enumerators.

I will follow your suggestions about using -999 as a code for ‘ impossible person ’. The variation (-2, -3, …) is indeed unnecessary. I tried a bit ?? -operator and failed. I will try some more with ?? and a rearrangement of the syntax.

Thank you!
Maria

To enforce the above it should be sufficient to check that the number of distinct respondents must be equal to the total number of respondents. Number of selections you probably know or specify already. Number of distincts you can get by applying Distinct()

The whole exercise is probably much simpler to do in a roster rather than on 8 of manually created copies of each question, and variable, and enabling condition, and validation condition, and error message (as you have probably already found out):

RESPONDENTS.Count(p=>p.respcode)==1

Perhaps more precisely: “When Alice is responding and selected, she must respond for herself! ” Since otherwise it seems the error message is blocking proxy responses, which you wanted to allow.