Survey123 functionality: calculate position in repeat group?

11526
24
04-07-2017 02:55 PM
MaxMarno
New Contributor III

Is there a calculation that will return the index or position of the current repeat set? This would be useful to pulldata and populate the default answers for each of the repeat questions based on the position in the repeat index.

0 Kudos
24 Replies
DougBrowning
MVP Esteemed Contributor

After some testing I got this to work for me.

So if my field is say Point_No and I have another filed called RecKey in the repeat 

then I add this to the Calculation of Point_No

count(${RecKey})

Works great.

Make sure to pick another field in the repeat.  Any will do just not itself since that throws an error.  
So count(${Point_No}) does not work for some reason.

Will this cause any issues?

Hope it helps.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Doug,

This will work unless you also are using default values in the repeat and a repeat_count - there's an issue where the defaults are not applied in that scenario.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Well after getting this out to the field we found an issue.  If a user goes back in a repeat it will recal as soon as they change repeat records - which updates the field to the current total vs what it was at the time.

So if they are on Repeat #2 then hit back to Repeat #1 it automatically changes the calc field from 1 to 2.  It also then wipes data from a relevant we have based on that field.

So as long as they just go forward it works but be careful using this!

Thanks

0 Kudos
ThomasPerriment1
New Contributor III

Consider including your calculation within a once() function. I have a log within a repeat in survey123, where users can enter a Depth From and a Depth To with comments on that depth range; users can add a repeat to have a series of From/To with notes. Outside of the repeat (hidden) I have a calculation to determine the max "Depth To" recorded, and and in the calculation field of my Depth From I have this max Depth To within the once function as 

once(max(${Depth_To}))

Which calculates it only once per repeat (upon creation of the repeat), so that when I go cycle back through repeats the value is maintained. 

Used the same to generate a start/stop watch to calculate standing time whilst on site. I used a single option likert "Stop" button as: {StandStop}, and a dateTime function relevant to: ${StandStop} = 'Stop' with the calculation: once(if(${StandStop} = 'Stop',now(),'')).

DougBrowning
MVP Esteemed Contributor

That works - thanks a lot! 

For everyone else here is how to do autonumbering.

In a repeat have a field with a calculate (it can be editable)

Use this formula subbing in any field in the repeat (except itself)

        once(count(${RecKey}))

I have never seen once before.  Is it documented somewhere?  I am surprised esri never mentioned this to anyone.

Thanks again.

ThomasPerriment1
New Contributor III

You’re welcome! I asked a similar question a month or two ago (regarding the “stop watch” function mentioned) and the Esri staff got in touch, mentioning the once() function.

Solved many issues!

0 Kudos
by Anonymous User
Not applicable

Half way down the page...I use it for the geopoint question in order to keep the field crews from accidentally adjusting the position after the initial location on a multi day survey for the same location.

Quick reference—Survey123 for ArcGIS | ArcGIS 

ThomasPerriment1
New Contributor III

Hmm that’s a great point, not something I had considered. Thanks for the input, Mike!

NicolasPfeffer-Taggart2
New Contributor II

Thanks a bunch Doug (and all who have suggested)! Any chance you could share an example XLS showing how you implemented autonumbering as you described? I'm trying to use the once(count(...)) method you described but I keep coming up empty. James Tedrick, I vote in favor of implementing the position(..) function. I've used it extensively in ODK and Ona with great success for this exact problem.

0 Kudos
DougBrowning
MVP Esteemed Contributor

My guess is you are trying to count itself?  You need to count some other field.

So

Both fields are inside the repeat

Field A  - has some default or calculated value

Field B - is the field you want the auto number to be in.  Field B has the calc  once(count(${Field A}))

Try that.