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)

I have tried above solution.
I always get output as zero only.
see attached form, csv and xml.
in column Hint, I have highlighted as Issue 2.
Thanks in advance!
4_farmer_onboarding_v1.xml (9.4 KB)
4_household_onboarding-form-designV1 - Copy.xlsx (28.9 KB)
land_db_new.csv (740 Bytes)

Your calculate was
count(instance('land_db_new')/root/item[hh_id=${hhid_qr_f} and system=${system_label}]/name)

Which was looking to count the column name in the CSV where hh_id & system matched.

But your CSV only had column headers srno,hh_id,parcel_uid,parcel_name,system

Change the calculate to
count(instance('land_db_new')/root/item[hh_id=${hhid_qr_f} and system=${system_label}]/srno)
and it will work.

3 Likes

great. works now.
Thanks a lot.. saved my day.