Selecting the oldest of a list of events

Dear all,

My questionnaire covers different problems that are divided per theme. I am struggling to solve a couple of issues and could not find an answer in the forum, hence I am posting here. I would be very grateful for your input or suggestions.
I would like to achieve the following:
Theme 1;
Q1) select what problems you have experienced
Q2) for those selected: when did this problem start
Then: select oldest problem for follow-up questions
Repeat this for multiple themes.
Then: select the oldest problem over all (across all themes) for further follow up questions.

Now, I am having some issues with getting this set up. I am using xls form and I have gotten this far, but chances are that I have made it way too complicated:

  • Per theme, I have created a group of select one questions to have respondents indicate problems they experienced. I used select one because I would like respondents to be able to indicate per problem if they have or have not experienced this, or if they prefer not to say.
  • for those problems selected, I will ask about the start-date. I also record the date of the interview. Using these dates, I calculate how long ago the problem started (${start_interview}-${start_problem}).
  • using calculate and the max() function, the longest duration is calculated.

There are some issues that I could use advice on:

  • After all this, I would like to include a note that states: I would like to ask you some further questions on [problem that is the oldest]. Now, max() returns the highest number of days that has passed since the problem started. Is it also possible to have max() or a similar function return the name of the item with the highest number? I was hoping to connect that to the relevant problem descriptions using if functions. If there is a better way to solve this, I would be very interested in your suggestions.

  • How does max() treat problems with the same duration? In case two problems have the same duration, it would be ideal if a problem for follow-up could be randomly selected out of those.

  • After going through all the themes, I would like to select the oldest problem over-all (so over all the different themes) for follow-up. What would be your advice in going about that?

Your advice or any suggestions would be greatly appreciated! Thanks a lot in advance.

As my description might be hard to follow, I have attached the test-excel file I have been working in.
test.xlsx (12.7 KB)

@giteLU, trying to simplify your issue. Please feel free to decline it if you think it’s now what you are looking for.

If I had to design this form, I would create a repeat group instead of a begin group. So the structure would be something like this:

begin_repeat
Q1. Select what problems you have experienced. (select_one question)
Q2. When did this problem (start-date)? (date question)
Q3. When did this problem end (end-date)? (date question)
Q4. Any other questions …
end_repeat

So with this, you could repeat all the questions as many times as you would like to repeat. You should be able to learn more about the repeat group function through this support article Grouping Questions and Repeating Groups.

You could use the max function as outlined in this community post discussed previously:

Maybe our valued community should also have some other workaround that could be simpler and handy for you.

Dear Kal_Lam,

Thank you for your reply and suggestions!
I looked into the repeat groups option, but after trying it out for a bit decided not to use it because the answer options differ between different groups. Also, I personally don’t really like that in repeat group instances the data output appears on different sheets.

I am still looking for the best way to select the oldest problem and refer to the associated labels, but I will have a look at the link you posted to try and solve that.

I might suggest you instead to put all your 11 criterion into a single ‘select all that apply’ select_multiple question, then iterate thru this list using a repeat group [hint: repeat_count = count-selected(${criteria}) ], and for each iteration ask for the date_started (for that particular criterion) and then calculate the duration from this.

Then, as @Kal_Lam suggests, use the max() function to pick the longest duration out of the repeat group.

1 Like

Note, getting the maximum value (from a repeat group) is fairly straight forward; just use max().

However, getting the other attributes associated with this value - eg the particular selection option name or its display label - is a bit trickier, but it can be done. Take a look at this:

The max_name has to use a little XPath ‘black-magic’ to find the option name associated with the determined maximum value, and the max_label then uses the jr:choice-name() function to lookup the label displayed for this option.

ListMaxItem.xlsx (18.6 KB)

1 Like

Apologies for the late reply, I got caught up in building other parts of the form.
Your solution is working well! I altered it a bit as I am not using repeat groups. Thanks for helping me out.

1 Like