I have an app that uses a 'household' parent case and 'member' child case. Within the 'member' visit form I want to be able to search for the # of other child cases indexed to that parent who meet a certain criteria:

In english: How many other child cases are indexed to this patient with the property mm_is_in_tb_treatment = 'yes'?

Instance path:

instance('casedb')/casedb/case[@case_type='household']/ ... 

and then I'm not sure how to specify this 'member' case's 'household', then filter for child cases of this household, then filter for

/mm_is_in_tb_treatment = 'yes'

Once I get the instance syntax correct, what is the output? I need the total # cases that meet that criteria.

  • Hi @Sathya, while these questions look programming oriented, these are actually just snippets of formula that go into text boxes on a web application. They are very similar to Excel formulas and are for advanced users. You can see previous discussion here: webapps.stackexchange.com/questions/103045/… Commented Feb 21, 2017 at 10:50
  • @BenRudolph thanks for clearing that up, will reopen Commented Feb 21, 2017 at 13:24

1 Answer 1


I'm assuming in this case that you've loaded a the member case into your form, and that you can load the member case ID id into


What you want to get is:

The count of all member cases which are children of this case's parent, for which the member case has the property mm_is_in_tb_treatment = 'yes'

For now we can create a new hidden value to store the parent household's case ID, since it'll make understanding the full query below easier.

New hidden value: /data/parent_id:

instance('casedb')/casedb/case[@case_id = /data/member_id]/index/parent

All cases which are children of that parent would be referenced as:

instance('casedb')/casedb/case[index/parent = /data/parent_id]

You can now add your new filter directly to the end of that statement and introduce the count

count(instance('casedb')/casedb/case[index/parent = /data/parent_id][mm_is_in_tb_treatment = 'yes']

If you wanted, you could further specify that you (for safety) only want to include children that are member cases and which are open. You can also collapse back the parent ID reference if you want a one-line expression:

count(instance('casedb')/casedb/case[@case_type='member'][@status='open'][index/parent = instance('casedb')/casedb/case[@case_id = /data/member_id]/index/parent][mm_is_in_tb_treatment = 'yes']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.