Select to view content in your preferred language

Conditionnally pulling data from previous repeat

424
3
07-07-2022 07:39 AM
AntoinePrince
New Contributor

Hi,

I am looking for a way to pull data from an earlier repeat section following conditions that I would determine. For example, I would like to pull the position index of a certain repeat entry if it fills those conditions.

Something like:

x = repeat_index where ((field_name_1 == 123) AND (field_name_2 == ''cheese''))

I know this is not the way it would be implemented in Survey 123. It's just to give a broad idea of what I need.

Thanks in advance!

0 Kudos
3 Replies
abureaux
MVP Frequent Contributor

I believe you are looking for indexed repeats.

Scroll down and look for "Return the index of a repeat record" and "Use values from indexed repeats" https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformrepeats.htm

0 Kudos
AntoinePrince
New Contributor

I get that you are refering to this request structure :

indexed-repeat(${question}, ${repeat_name}, index)

Now, I do have the <question> and the <repeat_name>. However, I would like to obtain the <index> based on conditions in the repeat table. Let's assume the following repeat table :

indexfoodamountname
0steak6paul
1tofu24alice
2cheese4eric
3brocoli56pamela
4tofu78amy

 

Would it be possible to pull the index value where 'food' = 'tofu' and 'amount' = 78?

0 Kudos
abureaux
MVP Frequent Contributor

Is there a risk of multiple items in this repeat matching your conditions?

If there is no risk of duplicate items, you could simply set up a calculate inside the repeat: if(selected(${food},'tofu') and ${amount}='78', position(..),'')

This will only contain your index when the conditions are met. You can then pull data using that index. If there is a risk of multiple items matching the conditions, you will need something different.

0 Kudos