Sum of different answers in categorial single-select questions for all elements in a roster

Hi everyone,

I’m struggling with a synthax issue.

I’ve a roster of household members. For each member, we ask his main activities, in a multi-select question called indiv_activ

Then, after the roster, we ask the respondent to pick-up the most important activity for the entire household, within a list restricted to those choice that have been choosen previously for individuals.
Therefore this single-select question has a filter:
mh_roster.Any(x=>x.indiv_activ.Contains(@optioncode)) // (hh_roster is the roster of members, and indiv_activ is the individual question about the main activities).
And is enabled only if there is at least an option (enabling condition: mh_roster.Any(x=>x.indiv_activ!=null)
This works.

Now, we want to ask about the second most important activity, at household level. This is where is becomes more tricky. I want to add a enabling condition, to avoid asking the question to a household, where, say, everybody would have the same activity (i.e. in the case there is no second most important activity, by construction).
The idea is to be able to count the number of different answer to the question indiv_activ, for all members of the household (all rows in the roster). So far, I’ve not managed to do this.
I’ve try an enabling condition like this:
mh_roster.SelectMany(x=>x.indiv_activ).Count() >=2 // this is not working

Someone ever encontered any similar issue? How would you fix this?

Thanks a lot!


EDIT: correction of the description of indiv_activ


  1. you are writing about a SUM of different answers, yet you apply the COUNT function. Which one is your intent?

  2. You wrote “this is not working”. I see two possibilities, either you get a compilation error, than what is the error? or your syntax compiles and the questionnaire when tested shows an incorrect behavior. Then specify for which inputs you get an incorrect output, and what is the correct one.

Best, Sergiy

Thank you Sergiy for your answer.

  1. I’ve actually tried both options. My intent is to count the number of different answers. For instance, if I have 3 members in the household, but all of them report the same activity, then, at the household level, I would like to disable the question about the second most important activity, which doesnt make any sense. I would like to create a “counter” of different answers.

  2. I don’t have compilation error, neither with Count() or with Sum(). But in the case of the example I explained above (3 members, all with the same activity), both formulas mh_roster.SelectMany(x=>x.indiv_activ).Count() or .Sum() return 3. The input I’m looking forward to get is a 1.

I hope I was clearer.



I realized I did not correctly specify my problem.

I was wrong about indiv_activ. This is actually a multi-select question, about all activities of a given household member.

Looks like I found the solution myself, using the Distinct() function.

mh_roster.Where(x => x.indiv_activ!=null).SelectMany(x=>x.indiv_activ).Distinct().Count()

does the trick.

Thanks anyway!

1 Like