# Puling values from the repeat to a calculation

492
2
04-29-2018 12:52 AM
Highlighted
by
Occasional Contributor II

Hi, we are trying to add a calculation that uses values from repeat records by pulling each one separately and dividing it by the sum of all.

For instance (inside the repeat):

 Specie Num of individuals Specie 1 5 Specie 2 6 Specie 3 7 Total 18

This is a calculation that we would like to perform (outside the repeat):

(5/18*ln(5/18))+ (6/18*ln(6/18))+ (7/18*ln(7/18)).

Is it possible to accomplish with a current version of Survey123?

Thank you

1 Solution

Accepted Solutions
Highlighted
by Esri Esteemed Contributor

Hi Guy,

Just checking, but the numeric values (5, 6, 7, 18) are based on the values within the repeat, correct?

This is technically doable within Survey123, though the workflow is not intuitive.  This can be accomplished by have a question within the repeat that does the calculation

`\${repeat_value} / sum(\${repeat_value}) * log (\${repeat_value} / sum(\${repeat_value}))`

and then have a question that sums the calculation in the parent form.

The issue is that the sum(\${repeat_value}) function will base its calculation initially on the value of the currently entered in values (i.e., 5 after the first repeat, 11 after the second, 18 after the third); the user filling in the form will need to page through the repeats after completion to update the calculation and get correct values.

2 Replies
Highlighted
by Esri Esteemed Contributor

Hi Guy,

Just checking, but the numeric values (5, 6, 7, 18) are based on the values within the repeat, correct?

This is technically doable within Survey123, though the workflow is not intuitive.  This can be accomplished by have a question within the repeat that does the calculation

`\${repeat_value} / sum(\${repeat_value}) * log (\${repeat_value} / sum(\${repeat_value}))`

and then have a question that sums the calculation in the parent form.

The issue is that the sum(\${repeat_value}) function will base its calculation initially on the value of the currently entered in values (i.e., 5 after the first repeat, 11 after the second, 18 after the third); the user filling in the form will need to page through the repeats after completion to update the calculation and get correct values.

Highlighted
by
Occasional Contributor II

Dear James,

Thank you for your prompt response. The equation works perfectly and solved the problem.

I was excited to see that.

Thanks again,

Guy 