Checking if an Entity Attribute Column Contains a Value

Dear community,
I want to check if an entity attribute column contains a value.
So I basically have a text field where the user enters an account number, and then a subsequent calculate field to search through the same_outlet_acc column of the entity list (which is supposed to contain string of some options [accounts] selected through multiple-select question at entity creation) to see if any field in that column contains the account number entered in the text field.

Below is how my entity list table looks:

Is my calculation correct? Because it returns nothing instead of 'yes' or 'no' and I'm not able to figure it out.
if(count(instance('visited_agents')/root/item[contains(same_outlet_acc, ${acc_number})]/same_outlet_acc) > 0, 'yes', 'no')

I'm sorry your question has sat without an answer for so long! Were you able to make progress? I'm not able to reproduce. Here's a test form I used to try out this concept: https://docs.google.com/spreadsheets/d/1CVq1KFMUy4j0OESeORqGKEds1hPRFZ9Z70byLkU5qM8/

I would recommend using selected instead of contains for the reasons described in this thread but I also tried contains and that worked as expected.

The trigger column expression isn't required in this case because your calculation is hidden. It's only needed to do a dynamic default that a user could edit. But again, it shouldn't be an issue and I've confirmed that it works for me with the trigger expression.

I think you're going to need to share more about your form and your Entity List if you're still stuck on this. Are you submitting with Collect or Enketo?

aha I managed to solve this problem!
Contains worked for me. I think the problem was around how I configured entities in xls form.

1 Like