Choice filter returns no values for Select_one question

1. What is the issue? Please be detailed.
I am using choice filter for select_one list. The select one question is mandate.
in few cases the choice filter gives 0 rows output.
How can I count the number of records from choice filter?

2. What steps can we take to reproduce this issue?

3. What have you tried to fix the issue?

4. Upload any test forms or screenshots below.

I have just done this, using a select from map appearance when I wanted to confirm for the user that the choice filtering did/didn't result in any values that would appear on the map.

Eg, I have a list of items scattered over many areas, I ask the user which area they are in (you could also ask which type of item they are looking at as well or instead, details in spoiler) as form value ${area}, these areas are on my list of items as a column with header location

The select is filtered with a choice filter as location = ${area}

Calculate the number of matching choices as:
count(instance('CHOICE_LIST')/root/item[location=${area}]/name)

filter by two values

(if you wanted to count/filter by area and type it would be count(instance('CHOICE_LIST')/root/item[location=${area} and type=${type}]/name))

You could then use the count value to make the select_one relevant as ${count_of_items}>0. If >0 it's true and the question is relevant. Or you could use it to make the question mandatory.

In fact, I have just added this relevance to remove the select from map when there are zero items on the map to select and it works but I seem to get a carryover value in the count sporadically when I change the value that it filters on from one with items to one without (i.e. Area 'has 10 items', change to area 'has 0 items' sometimes shows 10 in the count note (incorrectly) but nothing on the map appearance to select (correctly))

1 Like

Hi,
Thanks for the fix.
But your solution seems to work when select options are part of choices list.
In my case i am using external CSV.
Would this work with CSV as well and how if yes?

Yes, I am actually using a CSV for my choices, it works fine.

eg, file is called itemsfile.csv and there are multiple different choice groups in it, with another column to identify them, eg a type column with values country, city, suburb

The select is of the form select_one_from_file itemsfile.csv, with a choice filter to get the correct set of options in the CSV, eg type = 'country' to limit choices only to countries.

The count is counting items in a CSV, eg to count all the choices in your CSV itemsfile.csv that match previous questions asking for the Country as ${countryname} and Suburb as ${suburbname} you could calculate:
count(instance('itemsfile')/root/item[country = ${countryname} and suburb = ${suburbname}]/name)