Recalculating fields within a repeat

746
2
07-23-2020 02:36 PM
JayPuckett
New Contributor

I am running into an issue using calculated fields inside a repeat.  The user enters a number into Field 1.  Field 2 sums the total values entered in all Field 1's within the repeat.  Field 3 divides Field 2 into Field 1 to get a percent coverage across all records. 

begin repeat

Field 1: ${enterAnumber}

hidden Field 2: sum(${enterAnumber})

hidden Field 3: ${enterAnumber} div sum(${enterAnumber})

end repeat 

Field 4 (outside the repeat) - how many records are greater than 20% of the total?

This works well for any given record in the repeat, but it only takes into account the sum of values already entered.  If a new record is added then Field 3 in the previous records do not update, which means my Field 4 calculation is incorrect.  Is there a way to force the calculations within a repeat to rerun?  If not, any other thoughts on how to approach this?

0 Kudos
2 Replies
by Anonymous User
Not applicable

Hi Jay,

What you are seeing is the expected behaviour. Calculations do not automatically update in previous repeats when new values are added to new repeats, as in many cases you may not want this to happen, and it may causes changes to existing historic data.

You need to navigate back through the existing repeats once the new values have been added to new repeats and select the re-calculate button to get those calculations to update.

The only other way to get this to work would be to move all the calculations outside of the repeat, and into the parent layer. Are you able to attach you xlsx form so we can take a closer look and see if there is a better way to set up your form to achieve what you are trying to do.

Regards,

Phil.

0 Kudos
rogue_recon
New Contributor II

Hey Phil, 

I am having the same issue. The user would need to cycle through all the repeats after they answer the last few questions for them to correctly calculate. I'm curious if I can do the opposite and calculate all my repeats in the primary survey.

Best, 

Eli 

0 Kudos