Calculation and repeats

Hi Mr Xiphware, ¿could you help me with the next problem? When I´m runnig the XLS Form, it shows me the next message:


Can you please post your original XLSForm to help correctly identify the exact cause of the error.

Of course, but in this moment the problem is another. I couldn't calculate multiples integer in a repeat option.

Help.xlsx (11.7 KB)

your two calculations - row 47, 48 - are outside the repeat group, but are attempting to directly reference fields inside the repeat group; this can only be done using an indexed-repeat() [otherwise how would you know which repeat iteration to grab the value from...]

Your form appears to be tallying the number of deliveries across various age/sex criteria. If you put a calculation inside the repeat to add up rows 6-18, say called ${subtotal}, then outside the repeat group you can have a single calculation ${total} = sum(${subtotal}) to give you the grand total. See sum() for details. I assume that's what you are trying to accomplish?

Yes, it is exactly what I'm trying to do, but ¿I could´t understand you very clear about what is the mistake that I have. Could you show me an example please?

Have a play with the following sample form. It shows how to calculate a subtotal within each repeat group instance, and then calculate an overall total using sum():

sumexample.xls (24.5 KB)

You can load and run it under XLSForm Online. Please note I assume all values are required so they must all be answered, otherwise you'll get 'NaN' as a total. If some of your summations are optional (which they will be if the associated question has a relevance field) then you will need to do some additional work to handle adding optional values.

1 Like

Perfecto! Perfect!

Muchas gracias amigo! Thank you very much my friend!

Bendiciones! Bless!

Hi Xiphaware, I'm so sorry, I have a question again. I have a problem with my xls form, but it´s not exacly an error. In the same form, I want to show the subtotal and the item that I have been selected previously in a repeat cicle. I attached the sumexample.xls that you had shared with me and I had added another fields that explain better what I want to show in the form. ¿Would you help me, please?

sumexample_edited.xls (30 KB)


Not clear your question but you can check the attached file. Let us know if it server your purpose.
sumexample_edited.xls (63.5 KB)

Thank you Arif, but I cpuld' resolve the situation. What I really want to show is that depend of the number of members that I have it shows me the one message about the member and the number of people of that kind of member. For example, if I selected 2 members of the family, the form shows me only the subotals and the member of each option, no more. I attached the example that I tryed to do. sumexample_edited.xls (31 KB)

Thank you for your help,