Pulldata with two lookup values

I have preloaded csv data from another form and I was able to return data with one loookup value. I'm wandering how to return data with two lookup value from the available csv columns?

Have you read through the preloading documentation here? For each value that you need to pull out of your csv data, you should be able to create a calculate field in your XLSForm that makes a call on pulldata.

If that doesn't answer your question, please provide more information on what you are trying to achieve. It might be helpful to show a portion of the csv and describe what information you are trying to pull out of it.

Given a single id, you can retrieve single values from the CSV and use that in the form. Let's say you have a CSV like this.

+----------+------------+-----------------+
| child_id | child_name | child_fav_color |
+----------+------------+-----------------+
|        1 | Bob        | red             |
|        2 | Sally      | green           |
|        3 | Jose       | yellow          |
+----------+------------+-----------------+

In this example, you can pass a child_id into pulldata, grab any child's name, and store it in a single calculate. You can also use another pulldata to grab any child's color and store it in another calculate.

Based on your post, I think you want to pass in two child_ids at the same time, and there's no way to do that. If you can describe more about your specific high-level goal, we might be able to offer a workaround.

2 Likes

Hi Yaw,

Let's say I want to target Sally that has favourite red color, how we do that in pulldata?

child_name child_fav_color
Bob red
Sally green
Jose yellow
Sally red
1 Like

This is currently not possible. And if you'd like to see it added to ODK, please file a feature request.

1 Like

I've been doing this by giving two pulldata requests in succession to filter the results. The first would be to pick the color from a list of all the colors (eg. red) and store that in a variable, and then get a list of all the names corresponding to the picked color in that variable.

2 Likes

You could also merge the keys in a calculation before sending it off to the lookup file. So instead of sending "Sally" as the key, send "Sallyred", "Bobred", "Sallygreen", etc.

If you are differentiating on two factors, then the key is really the combination of those two factors.

Jason

4 Likes

3 posts were split to a new topic: Get multiple variables with same prefix using pulldata

Can you give me a sample of your work for this? Or anyone else?

Good day;
I am just struggling to get the pulldata fulfilled. I have a file for Identification Information for Enumeration Areas, I am just failing to link it to the form.

pulldata(‘neussl’, ‘str_no’, ‘district’, 'loc_type', 'ea_code', 'sr_no', ${sr_no})

This is the error I am getting " FormLogicError: pulldata with incorrect number of parameters found: pulldata('neussl','str_no','district','loc_type','ea_code','sr_no',"

I really need your help. Thank you in advance

@tebok, pulldata only works with 4 parameters. Those parameters are, in order: CSV file, column with value, column with key, lookup variable. In your example, you have 7 parameters.

Try to get the examples here working first:

1 Like

got that sorted, thanks.
now i got a massive error on indexed repeat - see the attachedsectione.xlsx (13.8 KB)

Check it and let us know if it works sectione.xlsx (18.9 KB)

It worked well, thanks, but i have about 5 types of questions that carries the same format. When i copy and paste the same formula, it does not display labels.

I have an issue with pull data,
Suppose you have a CSV file named "data.csv" with the following content:

medication dosage patient_type
Aspirin 100mg Adult
Paracetamol 500mg Adult
Ibuprofen 200mg Adult
Benadryl 25mg Pediatric
Amoxicillin 250mg Pediatric

In XLSForm, how can you use pulldata with two conditions to retrieve the dosage based on the medication and patient type.
Does pulldata('data', 'dosage', 'medication', ${medication}) and pulldata('data', 'dosage', 'patienttype', ${patienttype}) work ?