Calculation Doesn't Fire Inside Repeat

03-29-2019 07:19 AM
Regular Contributor
integertotal_repeatsNumber Repeatscount(${dummy_counter})
decimalmean_vegAverageround(sum(${num_veg}) div ${total_repeats},2)
begin repeatquadsQuad Data Entry
hiddendummy_counterincraments repeat count1
integernum_veg# Vegetative0
decimalnum_veg_sqdifSq Difference Vegpow((${num_veg} - ${mean_veg}),2)0
end repeat

A portion of the XLS form is above, the problem is that the num_veg_sqdif doesn't automatically re-calculate after new repeat records are added. Notice how the calculation uses the mean of all values inside the repeat. This mean value changes when a new repeat is added, thus all previously calculated num_veg_sqdif values need to be re-calculated.

The only way to do that is to manually page back through the repeat records and hit the arrow button (looks like the recycle symbol) on the num_veg_sqdif field.

The survey123 docs say this: "Unlike the default column, which is evaluated only when the survey is opened or the question becomes relevant, calculations are evaluated every time answers in your survey that are inputs to the calculation change or become relevant."

Why isn't the re-calculation happening inside the repeat, is this expected behavior?

BTW: this entire post would be a moot point if there were  a few more aggregation functions that work with repeats, submitted idea here:  

0 Kudos
1 Reply
Esri Esteemed Contributor

Hi Dan,

With regard to the form you have, the issue is that the average updates, but the square difference calculations for the repeats not currently in focus do not update.  This is expected behavior for Survey123.  We are working on supporting more complex calculations such as standard deviation through javascript functions that can use a repeat's entries as input parameters; expect to see information in the Early Adopter Community soon on this.

As for additional aggregation functions, we are limited in our inclusion by the XLSForm specification - ODK XForms Specification 

Tags (1)