# Calculate values from repeat group

Hi,

How do I calculate values, taken as input in repeat groups? For example, I have a repeat group and I would like it to be repeated 3 times and I will provide 3 values for 3 repeats. After repeats, How do I calculate values from the repeat groups?A form is attached here for your input.

Thanks,
Imran
repeat_group.xlsx (9.6 KB)

2 Likes

Hi,

I would use indexed-repeat in the case you have a constraint for the number of repeats allowed.

In your example, you have a maximum of 3 repeats, meaning you would need 3 calculate rows like this:

``````+--------------+--------------+-----------------------------------+---------------------------------------------+-----------------+
|     type     |     name     |               label               |                 calculation                 |  repeat_count   |
+--------------+--------------+-----------------------------------+---------------------------------------------+-----------------+
| integer      | total_people | How many people will be surveyed? |                                             |                 |
| begin_repeat | repeat_name  | Group 1                           |                                             | \${total_people} |
| integer      | value        | Value:                            |                                             |                 |
| end_repeat   |              |                                   |                                             |                 |
| calculate    | calculate_1  |                                   | indexed-repeat(\${value}, \${repeat_name}, 1) |                 |
| calculate    | calculate_2  |                                   | indexed-repeat(\${value}, \${repeat_name}, 2) |                 |
| calculate    | calculate_3  |                                   | indexed-repeat(\${value}, \${repeat_name}, 3) |                 |
+--------------+--------------+-----------------------------------+---------------------------------------------+-----------------+``````
3 Likes

Hi Jorge,

Thanks for your response. I am wondering how do I manage if the number of repeats is not defined. For instance: a user may select 3 repeats other may select 5 repeats.

Thanks once again,
Imran

1 Like

You can use the `sum` function to sum all the values with a given `name` in a `repeat`. See an example based on what you shared here.

6 Likes

Hi Hélène,

Thanks so much. This is so helpful.

Imran

1 Like

3 posts were split to a new topic: Calculation depending on previous selection

Hi,
Did you ever figure out how to store variables to calculate dynamically based on the number of count?

THank you

Thank You so much