Sum calculation within a repeat-group to get subtotal

Hi there. I would appreciate your guidance here.

I’m trying to perform a sum calculation as a subtotal of one nested group

Highlighted line should only sum income for the correspondent g_person instance, so I get as many subtotals as instances of g_person

However, it sums for all instances

Is there any way to specify the nodeset for sum(nodeset) as an instance of g_person?

sum within repeat-group.xlsx (9.8 KB)

Thanks :raised_hands:

@sergiousme, this post discussed previously should help you solve your issue:

The problem you are seeing is a known issue specifically with how Enketo handles references within nested repeats. The workaround is that with Enketo you have to use an explicit relative path to the XML element being summed in the nested repeat (instead of the usual ${foo} which basically becomes an absolute path…). This is probably best explained just by giving you the code :slight_smile:

Take a look at this form, it should correctly sum values from the inner and outer repeat groups accordingly.


NestedRepeatSubtotals.xlsx (14.6 KB)

2 Likes