Append Ranked Choices

I have two select questions which are ranked differently.
I would like the respondent to see how they ranked the two groups. this should just be a list of how they ranked all the items.
I have tried to put it in alist but they dont appear as a list but as a continuous list.
how can I do this in ODK?

Welcome to the ODK forum, @ferd! We're glad you're here. When you get a chance, please introduce yourself here. I'd also encourage you to add a real picture as your avatar because it helps build community!

Are you using XLSForm to create your survey form? Are you able to post your survey questions here?

It's not clear to me how your form is setup... is the first select question for the top rank and the second question for the second rank? Are you using the rank widget? Something else?

Hi @danbjoseph,
please take a look at my survey. CPS_TEST.xlsx (17.9 KB)
Placing_Combinations.csv (2.9 KB)

Try this:

"concat(
	if(count-selected(${cps_work_prefer_rank}) >= 1, 
	 concat('1. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 0),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 2, 
	 concat('2. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 1),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 3, 
	 concat('3. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 2),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 4, 
	 concat('4. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 3),'${cps_work_prefer_rank}'),'

	 '),''),
	if(count-selected(${cps_work_prefer_rank}) >= 5, 
	 concat('5. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 4),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 6, 
	 concat('6. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 5),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 7, 
	 concat('7. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 6),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 8, 
	 concat('8. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 7),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 9, 
	 concat('9. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 8),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 10, 
	 concat('10. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 9),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 11, 
	 concat('11. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 10),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 12, 
	 concat('12. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 11),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 13, 
	 concat('13. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 12),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 14, 
	 concat('14. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 13),'${cps_work_prefer_rank}'),'

'),''),
	if(count-selected(${cps_work_prefer_rank}) >= 15, 
	 concat('15. ', jr:choice-name(selected-at(${cps_work_prefer_rank}, 14),'${cps_work_prefer_rank}'),'

'),'')
)"

...and so on

CPS_TEST-v2-jef.xlsx (33.9 KB)

You'll see I made some modifications to the form just to make it easier to test out this approach.

Note that this does not work in Enketo for some reason. But the rankings do appear in Collect.

Of course, I'd like a more elegant solution, but there is not a built in function that I am aware of that can do this. However, I'm not too familiar with the rank widget, so it may be that someone else has a more elegant solution.

It's in the ODK roadmap to upgrade Xpath to allow for an iteration or glob-style syntax. That would allow for a solution without having to statically code every choice option.

1 Like

Hi @Joseph_E_Flack_IV,
The formula worked fine had to amke some little changes though. Thank you so much.
I will essentially use it in enketo; not sure whether it will work there.

Glad to hear it. Good luck!

Another option you may want to consider is to later show a rank question with the value from the earlier question but that is read only. This XLSForm shows the concept. Be warned that this uncovers two bugs in Collect -- read-only doesn't work for rank and there's a crash when trying to modify a rank in a field-list. I've created issues for both and they will either be fixed for the upcoming release or soon after. Once those are addressed, the "Rank items" button would be disabled to prevent re-ranking.

I don't think it would help in this case because selects and ranks store their values as space-separated strings, not as nodesets.

I just realized that search() does not work in enketo. How would I convert the csv into and xml which can then be used in enketo.

Just linking this as it seems it's a duplicate: https://groups.google.com/forum/#!topic/enketo-users/nlIBpaLfJ-o