Hello,
I need to filter list of name with age>15 from a roster and display all names in another variable outside the roster. How can I do that
Can you describe your use case?
In any case, assuming you have a list question (listq
) that triggers your roster (roster_name
) in which the age question (age
) is located, you could do the following:
A. Create a new macro, e.g. called $concat_age15
with following content
/* Array with indices of all age 15+*/
int[] indices = roster_name.Where(e=>e.age>=15).
Select(e=>e.@rowindex+1).ToArray();
/*Go through all items in index and concatenate the respective names*/
string concatenatedNames= string.Join(", ", listq
.Where(b => indices.Contains(b.Item1))
.Select(b => b.Item2));
return concatenatedNames;
B. Create a variable (names_age15
) of type string
outside the roster with following expression:
(new Func<string>( () => {
$concat_age15;
})).Invoke()
That should give you the names seperated by β,β which you can use to display in static texts and the like.
Or you could simply skip step A and create the variable with folowing expression:
string.Join(", ",
/*Go through the list question*/
listq.Where(b =>
/*Create Array with rowindices of persons aged 15+*/
roster_name.Where(e=>e.age>=15).
Select(e=>e.@rowindex+1).ToArray().
Contains(b.Item1)).
/*Select the names specified in List Question*/
Select(b => b.Item2))
Thanks very much, it is working fine in static text. But how can I use it as filter to listq question?
Thanks
Do you want to have them LIST the same persons again?
Or do you want to reference the list of members in a single- or multi-select question (such as βWho is the main decision maker in the household?β). In this case, the source of categories of your categorical question should be binded to your roster roster_name
which allows you to add any filter condition that references most questions asked inside the roster (e.g. age>=15
).
If this is not what you are after, kindly clarify your use case and structure of questionnaire.
Yes, I need this βOr do you want to reference the list of members in a single- or multi-select question (such as βWho is the main decision maker in the household?β)β
Many thanks, it works now
Our public example questionnaires are abundant with examples of such situations. Consider e.g. the βSocialβ section in the βPublic example User questions and common patternsβ questionnaire.