Generate variable with household members' names

Hello Survey Solutions Team,

I have a related query to this. I need to make a string variable to store the household members given on the list based on the condition that the members are aged 15 and above and are of a selected gender.

String.Join(", ", members_list.Select(x=>x.Item2).Where(x=>hhmembers.Any(x=>x.age>=15 && x.Sex==interview_gender)))

Above is the code I currently have. It gives me the full member list, it does not give me the the filtered list as I want.

members_list is a list type question to list out household members
hhmembers is the roster which takes members_list as a source question.
age and Sex are variables within the hhmembers roster
interview_gender is a variable outside the roster to select Gender of the eligible members that needs to be stored in the string variable.

appreciate the help,

Thank You!

It probably gives you the full list of members as long as there is at least one member of the group of interest.

Instead of :

try:

String.Join(", ", members_list.Where(
  x=> (x.age>=15) && (x.Sex==interview_gender)
).Select(x=>x.Item2))

Best, Sergiy Radyakin

Hi @sergiy,

Thank you for the prompt response. Unfortunately, it throws an error.

*‘TextListAnswerRow’ does not contain a definition for ‘age’ and no accesible extension method ‘age’ accepting a first argument of type *
‘TextListAnswerRow’ could be found (are you missing a using directive or an assembly reference?)
*‘TextListAnswerRow’ does not contain a definition for ‘Sex’ and no accesible extension method ‘Sex’ accepting a first argument of type *
‘TextListAnswerRow’ could be found (are you missing a using directive or an assembly reference?)

I believe that it could be because both age and Sex are within a roster called hhmembers to which we are not referencing in the code suggested.

Any further help would be appreciated.

Thanks!

See this example:

The expression used is basically the following:

String.Join(
    ",",
    R_MEMDEMOG.Where(
      x=>x.memb_age>=15 && x.memb_sex==resp_sex
    ).Select(
      y=>hmembers.First(z=>z.Item1==y.@rowcode).Item2
    ))

Hope this helps, Sergiy

It now works as I intended to. Thank you for the help!