Relevant formula for range of choices

I want to know the code to type in relevant that will give me the chance to skip a question when some number of choices are selected.

If you are authoring your form in a spreadsheet using the XLSForm syntax, you can use a relevant column as described here in the documentation.

Hi @danbjoseph,

I have the same question, and I'm afraid I don't understand what syntax to use with just the number - or range as OP mentioned - of selections. The documentation gives examples of specific selections, such as:

selected(${favorite_topping}, ‘cheese’)

Whereas, what I feel @simondonkoh I are asking is if the syntax for the number of selections could be:

selected(${favorite_topping}, >= 2)

if at least 2 toppings were selected.

Thank you for your expertise!

EDIT: Maybe use 'count-selected(.)<=2' somehow?

@simondonkoh ,

I think I found at least some of the answer you need, based on something @yanokwa wrote some time ago:

count-selected(${your-variable-name} >= 2    

I imagine you'd be able to indicate ranges by using:

count-selected(${your-variable-name} >= 2 and <=10

But I'm less sure about that last part!

Hi @simondonkoh and @awiggin,

You can try: (count-selected(${your-variable-name} >= 2) and (count-selected(${your-variable-name} <=10)


Hi @awiggin does his response answer your question? Also, welcome to the ODK forums. It'd be great if you could add a profile image and post an introduction to the community forum thread: Introduce yourself here!

And thanks @Souirji_Abdelghani! Also, you can format code in your post by wrapping a part of the text in single ` or by adding a line above with ```plain and below with just the three marks and no word "plain"

So it will display like this: (count-selected(${your-variable-name} >= 2)


(count-selected(${your-variable-name} >= 2) 

Sometimes it can make it a little easier to read.

1 Like

@danbjoseph and @Souirji_Abdelghani,

To be fair, it wasn't my question or my thread. I just jumped in to add some possibilities and more detail. I'll leave it to the OP (@simondonkoh) to make that call.

For my part, I figured my part out from info helpfully posted by @yanokwa a year ago - so thanks for having a good search function for the forums!

Many thanks!


Hi @danbjoseph,

Thanks for this useful information about formatting answers.

1 Like