I have a survey where I am capturing the height of trees in a repeat, and then later on in the survey, I calculate the average height of these trees and then the values for 20% above the mean, and 20% below the mean. Now I need to do a count of the number of trees that are more or less than 20% above/below the mean.

Is this at all possible?

I have tried using the logic of

if(${height} > ${top_from_mean}, '1', if(${height} < ${lower_from_mean},'1', '0'))

inside the repeat, but this seems to write a static value to the field in the order that the data is captured, rather than a dynamic value that calculates as the average and top_from_mean values update. If I put that calc outside of the repeat it won't do the calc on the individual values and I won't get a count.

Any suggestions? Would it be easier to do this in Arcade on the data after it is submitted? We did want to present the results as the survey is completed to pass/fail the sample plot.

The formula you have goes in the repeat. But change your string '1' to a number 1. Then set the bind:type field to int (otherwise it concats so 1111 instead of 4).

Then outside of the repeat use one of these formulas.

sum(repeat) Returns the sum of all responses to a given question across repeats. sum(${question})

count(repeat) Returns the amount of responses to a given question across repeats. count(${question})

See here for more Formulas—Survey123 for ArcGIS | Documentation

hope that helps