Conditional sum of integers from nested repeat groups with multiple select question

Hi everyone. Hoping someone can help me with this.

With reference to the attached screenshot, I am trying to sum up the total pieces for each fruit bought from different purchases (i.e., purchase period or purchase channel). For this, I initially created a repeat group (purchases) within another repeat group (pieces), but I am having a difficulty in doing the sum portion given the challenge coming from the undefined repeat loops and options in the select-multiple question. I have tried mixing up indexed-repeat and sum for repeats but it's not working properly.

Also, I am planning to expand this design with a longer list of fruits once I am settled with the flow hence, if there is another way to simplify or customize the design depending on the selected fruits, that would be great.

Thank you in advance!

Hi @hm11
We're glad you're here. When you get a chance, please introduce yourself on this forum thread.

Could you attach your xls form not just a screenshot? It would be easier to help you.

hi @Grzesiek2010 , here's the xlsform I am currently working on, for your reference. and as i have already mentioned above, note that once I figure out the design, I need to rerun using a longer list of fruits. hence, if there is another way to simplify the design (i.e., not needing to create a calculation for each fruit), that would be great.

Sample Sum per Option.xlsx (10.7 KB)

Thank you!

This should work: Sample Sum per Option.xlsx (7.8 KB)
but if your list of items is long it might be difficult to repeat all the items.

Hi @Grzesiek2010 , yes, there is a need to copy the calculations for each item in the list if using this design. Nonetheless, this works! Thank you so much! Really appreciate your input!