I have a Select_Multiple and then a Rank Question like this, which I retrieved from here. I’ve added some followup calculation to determine the value of the nth item that has been ranked. These calculations are showing up in Enketo and ODK Collect (even though Enketo cannot change the rank items) but nothing is showing up in Web Forms. I will note that when submitted with a Web Form, the items are properly displaying in the submission, but not properly displaying in a note or so that they could be used as choice filters, defaults, etc. for future questions.
On a separate note, I couldn’t find this anywhere on the forum any mention of retrieving the nth value in a rank question or anything that is a space separated field. ChatGPT started making a formula with the tokenize() function, which was short and looked really nice, but that errored out. The formula below (Cell C16 of XLSForm above) can be used in excel to produce the quite lengthy formula for retrieving the nth value from a rank question
Well selected-at() shows the same behavior in webforms…so at least this post isn’t a total waste.
@ahblake , do you know how to flag/tag the core team on the forum so that the following message gets seen? Not sure who individually to tag or if it is just assumed someone from the ODK team will see this and address it.
So the Kapa AI definitely didn’t give me anything to work with on that regard and my baseline assumption was that anything that basic it would have been able to handle. Looking at the https://docs.getodk.org/form-operators-functions/#selected-at portion of the docs, the word rank doesn’t actually show up there at all, which is probably why it wasn’t showing up in the AI /searches I was doing. Looking at the site map on the right hand side of the Form Operators docs page selected-at falls under selects, which makes sense, but maybe this is just one of those scenarios where rank questions falls through the cracks since there isn’t really a great place to match it with selected-at().
I know that it’s important to not have the docs get too long and crazy, but has the idea ever been discussed to have some sort of connection or section where questions types are matched with commonly used functions/form operators? Maybe like a more examples part of each question that could be a group that is collapsed by default or something? I know there are often examples in the question types, I just feel like those could be more extensive.
I need to remember to search the docs first rather than using AI…on that note…the current Search Dialogue really makes it hard to do this…
When clicking on the Ask AI magnifying glass the dialogue window comes up and in the upper right hand corner you can choose between Ask AI and Search window. After clicking Search, typing in your query and pressing enter on the keyboard…IT STILL DEFAULTS TO AI! Can this be changed? As a user I already feel like I’ve tried to avoid the AI specifically by clicking the Search option, so to have AI be the first response is really frustrating.
Here is what I got when I thought I was searching the docs and it went to the AI, unfortunately I don’t have the original prompt I typed in
To get the nth value (for example, the 2nd or 3rd ranked item) from a rank question in ODK, you need to work with the value saved by the rank widget. The rank widget stores the selected options as a space-separated ordered list, where the order reflects the user's ranking (first item = top rank, second item = second rank, etc.) Rank widget documentation.
However, the knowledge sources do not provide a direct built-in function in ODK XLSForm to extract the nth value from this space-separated string. You would need to use string manipulation functions, but ODK's support for such operations is limited and not as straightforward as in some programming languages.
If you need to access, for example, the second ranked item, you would typically need to use a combination of substring and regular expression functions, but the exact method is not detailed in the provided knowledge sources.
Summary:
The rank widget saves the order as a space-separated list.
There is no explicit, documented method in the knowledge sources for extracting the nth ranked value directly in ODK XLSForm.
You may need to use advanced string functions or process the data after export.
If you need a workaround, consider splitting the ranking into separate select_one questions for each rank, but this is more complex and less user-friendly than the rank widget itself Forum discussion on ranking.
If you need further help with a specific use case, please provide more details, and I can check if there are any relevant workarounds in the knowledge sources.
Here is another query on the AI that didn’t get the selected-at function:
nth value rank question
To create a "nth value rank question" in ODK, you can use the rank widget. This widget allows users to order a list of options, and the result is saved as a space-separated, ordered list of the option names. For example, if your options are A, B, C, and D, and the user ranks them as B, D, A, C, the value saved will be b d a c.
If you want to extract the nth ranked item (for example, the 2nd ranked choice), you will need to process the space-separated string. However, the knowledge sources do not provide a built-in ODK function to directly extract the nth value from the rank widget's output within the form itself. This kind of processing is typically done during data analysis after export.
Summary:
Use the rank question type to collect ranked responses.
The output is a space-separated list in order of ranking.
Extracting the nth value is not natively supported in the form logic; it should be done during data analysis after data collection.
For more details on the rank widget, see the official documentation: Rank widget.
A simple change with from helps the AI enough to get it…weird
nth value from rank question
To get the nth value from a rank question in ODK, use the selected-at() function. The rank widget saves the ranked choices as a space-separated ordered list, so you can retrieve the nth item (zero-indexed) like this:
selected-at(${rank_widget}, n)
For example, to get the first ranked item:
selected-at(${rank_widget}, 0)
To get the second ranked item:
selected-at(${rank_widget}, 1)
This method is documented in the ODK functions reference and works for rank questions because their data structure matches that of select_multiple questions, which selected-at() is designed to handle Form Operators and Functions > Select questionsRank widget.
@Tyler_Depke Thanks for raising this. The ultimate cause of the blank notes is this issue which has recently been resolved and released though is not yet released in Central (coming soon!). I’ve tested your form on the web forms preview which has the latest release and everything seems to be working as expected.
I had this happen also, to allow 'search' to function, I had to open the search dialogue, change it from 'Ask AI' to 'Search' at top right, type in my keywords and not press enter. The results would appear below the 'Get an instant AI answer' bubble.
But I retested just now and hitting enter immediately or after the search results appear doesn't trigger kapa anymore. so