`sum()` in nested repeats


(jules rugwiro) #1

I need help in summarising two integer fields collected in nested repeats using sum()

I am using ODK collect to gather stock levels across store countrywide. I used two repeats to achieve this:

  • The first repeat iterates though commodities (pre-selected in a select_multiple) and inside the first repeat, the user mentions which batch numbers were used to receive stocks.
  • For each batch, I ask Qty received, and current stock

I now want to summarise the stock levels by aggregating Commodities by their batches (One commodity can be distributed in several batches)

I used the sum() outside the second repeat(batches) but inside the commodity repeat, it however generates errors requiring indexed repeats, and i don't see how to a-chive this since i want to aggregate all batches instances per commodity.

Any help will be highly appreciated


(Dr. Gareth S. Bestor) #2

Could you perhaps post your form? Its a bit difficult (for me) to determine precisely what you are trying to accomplish from your description... I have a vague idea, but the form would help immensely.

I suspect you might want to do a sum() - contained within in the top repeat (eg call it ${nested_sum}) - of certain field(s) of interest lying within the nested repeat. Then on the outside after the top-level repeat, another sum() to add up the ${nested_sum}.

But that's just a bit of a stab in the dark without the actual form to look at :slight_smile: