Sum() of certain repeats inside repeat

Hi Friends,

Is it possible to write syntax in xlsform that gives sum() value of certain repeats inside the intended index of repeat ? So far, it is possible to get sum() inside of each repeat group as @Grzesiek2010 suggested earlier.

My scenario is something like this -
Suppose, a tourist bus coordinator is asking about the food expenditure of every passenger traveling in a single bus. I want to get total food expenditure of first 5 passengers inside the fifth repeat group, and then after asking to 3 passengers, total expenditure of those 3 passengers inside the eighth repeat, and so on.

If possible, is there any idea to write such syntax in xlsform? Sincere request to ODK friends for this support.

Raj

It may need tested but can this not be achieved by having the sum() outside the smaller repeat group but inside the larger one?

I would test that first. if it fails then things are going to get a lot more complicated

Hi @noel_cartong,
Thanks for the attention, would be glad if any possible solution.
Raj

reepat_test.xls (52 KB)
it looks like you don't need to add anything complicated, you just have to put your calculations in the correct places (see example).

Hi @noel_cartong,

Thanks for your follow up. Can this be possible with not-nested repeat? If this can be done, my enumerators would receive my questionnaire more comfortable because they can get confused with repeat inside repeat in number of situation.

Thanks in advance!
Raj

if there's no nested repeat then I don't see where the complication is. its just a sum calculation and you put it outside the repeat group.

Hi @noel_cartong,

I would like to draw your attention here -

Kind regards,
Raj

OK but without nested repeats how does the form know that the first 5 people are one group and the next 3 another group? How does it know which people to group together?

Hi @noel_cartong,

Thanks for your follow-up and support.

Is there any way to get the total expenditure of first 5 passengers' food? I hope ODK form is much capable of holding this kind of programming as I follow some very exemplary forms programmed by ODK experts in this platform. Single repeat group (not nested one) will significantly reduce my enumerators' confusion while in field.

Happy new year 2021 !

Regards,
Raj

Have you tried something like this maybe?
sumTest.xlsx (5.1 KB)

Hi @Grzesiek2010,

Thanks a lot for your response. That works partly.

When the enumerator gets to repeat 5 (say), she/he is to ask a question - 'Do you want to add previous (5) expenditures including this?'. If chosen 'Yes', then only he/she is going to get the value of those 5 repeats' expenses. And, she/he should be able to take the chance of getting sum/add value in any number of repeat instance.
I hope this will help clear more.
Happy new year 2021 and stay safe and healthy!

Raj

Do you need to display that additional question just after filling 5th group? Orb maybe you can have that after filling all repeats?

Inside the 5th (say, maybe 6th or 8th) repeat group, I want to get the sum value of all current and previous repeats' expenses. To get that sum value inside a particular repeat, I want to ask whether to get the sum inside the same repeat group.

So maybe this:
sumTest.xlsx (6.2 KB)

Hi @Grzesiek2010,
Thanks a lot, I went through the example form.

Dynamically, what if I ask the question 'Do you want to add previous (6) expenditures including this?' or 'Do you want to add previous (7) expenditures including this?'' in the 6th or 7th repeat? In your example form you have fixed it for 5 repeats just, it could be inside any repeat.
Can the sum value be got in not-nested repeat in such a situation? Is there any example? kindly please.

Regards,
Raj

You have two options use the solution and copy calculations so that the question is displayed after all repeats (or where you need it) but it will be complicated or use nested repeats.

Hi @Grzesiek2010,

Again with the same thread!

I tried nested repeat in the case of my survey, that works fine for getting the sum() of certain number of repeats. However, for follow-up questions as per the collected responses in the nested repeat, accessing those response values in the follow-up nested repeat using the syntax example -indexed-repeat(${work_title}, ${second_repeat}, position(..), ${top_repeat}, position(../..)), seems not working in the attached form. I am on with ODK Central version v1.2. I ask specially for this solution in Enketo web form, it is working in fine in the super ODK Collect.
Nested Repeats.xlsx (11.3 KB)

Please help me to figuring out the solution.
Thanks.

Kind regards,
Raj