# Repeats groups within repeat groups

**URL:** <https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992>\
**Category:** Support\
**Created:** [November 16, 2015, 7:33pm UTC](https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992 "2015-11-16T19:33:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayub](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ayub/32/17023_2.png) [@Ayub](https://forum.getodk.org/u/Ayub)\
**Post date:** [November 16, 2015, 7:33pm UTC](https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992/1 "2015-11-16T19:33:19Z")

</div>

Hello ODK Community,

I would like to understand whether it would be a good idea to use repeat  
groups within repeat groups, the scenario is that there could be variable  
number of people added and then for these people we can add different  
number of household members (so technically this becomes a repeat within a  
repeat i.e. people added through indexed-repeat then while looping over all  
people there'd be a 2nd repeat at household level and on this same level  
another repeat to ask questions about each HH member). It would be best if  
it could be handled on the same form (as some constraints can be ensured  
e.g. all people were added or not etc).

Can there be any data accessing problems/issues (as data might be  
differently structured).

I would highly appreciate any ideas / workarounds to handle such cases.

Thank you,

Best,  
Ayub

P.S: I have tried a small form (attached) and tried it on the android, it  
seems to work fine.

[repeat.xml](https://getodk.b-cdn.net/uploads/default/original/1X/3f623596525a75ba25b5619e64b577951b4e316a.xml) (1.79 KB)

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [November 16, 2015, 8:56pm UTC](https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992/2 "2015-11-16T20:56:06Z")

</div>

Writing constraints that work correctly on repeat groups is tricky.

They will often work correctly when you have just one repetition, but fail  
and Force Close ODK Collect if you have two or more repetitions.

This is a form design and testing challenge. Search for current() and  
"relative XPath" on our lists for information on writing these so that they  
work.

Nested repeat groups work fine when exported via ODK Briefcase (you will  
have 3 .csv files: for the form, the sub-form, and the sub-sub-form). You  
then need to stitch these together to re-assemble your data set.

When using the publishers, there may be problems tying the various nested  
records together. I think it is broken for one or both of Google Sheets  
and Fusion tables. You should test to make sure you can tie the  
sub-sub-records back to the appropriate sub-record and record.

> **···**
>
> On Mon, Nov 16, 2015 at 11:33 AM, Ayub wrote:
> 
> > Hello ODK Community,
> > 
> > I would like to understand whether it would be a good idea to use repeat  
> > groups within repeat groups, the scenario is that there could be variable  
> > number of people added and then for these people we can add different  
> > number of household members (so technically this becomes a repeat within a  
> > repeat i.e. people added through indexed-repeat then while looping over all  
> > people there'd be a 2nd repeat at household level and on this same level  
> > another repeat to ask questions about each HH member). It would be best if  
> > it could be handled on the same form (as some constraints can be ensured  
> > e.g. all people were added or not etc).
> > 
> > Can there be any data accessing problems/issues (as data might be  
> > differently structured).
> > 
> > I would highly appreciate any ideas / workarounds to handle such cases.
> > 
> > Thank you,
> > 
> > Best,  
> > Ayub
> > 
> > P.S: I have tried a small form (attached) and tried it on the android, it  
> > seems to work fine.
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)

---

<div class="post-metadata">

**Author:** ![Ayub](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ayub/32/17023_2.png) [@Ayub](https://forum.getodk.org/u/Ayub)\
**Post date:** [November 18, 2015, 6:10am UTC](https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992/3 "2015-11-18T06:10:30Z")

</div>

Mitch,

I tired with little extended version of the form but pulldata() stoppped  
working in 2nd/nested repeat group (paths should have been relative i  
guess). Is there any example form that I could look into which uses similar  
concepts like relative XPath and current() that would be great help.

I've searched into ODK Community group, but couldn't find any specific  
answers to it.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![Mitch\_S](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@Mitch\_S](https://forum.getodk.org/u/Mitch_S)\
**Post date:** [November 18, 2015, 8:01pm UTC](https://forum.getodk.org/t/repeats-groups-within-repeat-groups/4992/4 "2015-11-18T20:01:35Z")

</div>

These might be useful:

[https://groups.google.com/forum/#!searchin/opendatakit/oldest$20youth/opendatakit/NIpaXpphD1w/eXuhwhleBgAJ](https://groups.google.com/forum/#!searchin/opendatakit/oldest$20youth/opendatakit/NIpaXpphD1w/eXuhwhleBgAJ)

[https://groups.google.com/forum/#!searchin/opendatakit/current()|sort:date/opendatakit/hSqzk0AN07Y/RqGn1akBBwAJ](https://groups.google.com/forum/#!searchin/opendatakit/current()%7Csort:date/opendatakit/hSqzk0AN07Y/RqGn1akBBwAJ)

[https://groups.google.com/forum/#!searchin/opendatakit/current()|sort:date/opendatakit/kHYalQ4Z1X8/lej1zLwcJgAJ](https://groups.google.com/forum/#!searchin/opendatakit/current()%7Csort:date/opendatakit/kHYalQ4Z1X8/lej1zLwcJgAJ)

[https://groups.google.com/forum/#!searchin/opendatakit/previous$20repeat|sort:date/opendatakit/fX5AvkRbpAI/-5s1wxW7b0kJ](https://groups.google.com/forum/#!searchin/opendatakit/previous$20repeat%7Csort:date/opendatakit/fX5AvkRbpAI/-5s1wxW7b0kJ)

[https://groups.google.com/forum/#!searchin/opendatakit/current()|sort:date/opendatakit/F5ZhjuO7\_20/i92Ff8NQAAAJ](https://groups.google.com/forum/#!searchin/opendatakit/current()%7Csort:date/opendatakit/F5ZhjuO7_20/i92Ff8NQAAAJ)

[https://groups.google.com/forum/#!searchin/opendatakit/current()|sort:date/opendatakit/oRx1uXnd4RQ/jTkPZc29CwAJ](https://groups.google.com/forum/#!searchin/opendatakit/current()%7Csort:date/opendatakit/oRx1uXnd4RQ/jTkPZc29CwAJ)

[https://groups.google.com/forum/#!searchin/opendatakit/current()|sort:date/opendatakit/bM-rgxC9rEw/tYtvRW9NiM8J](https://groups.google.com/forum/#!searchin/opendatakit/current()%7Csort:date/opendatakit/bM-rgxC9rEw/tYtvRW9NiM8J)

And there is a known issue where "current()/." within a selection choice  
filter references the enclosing group and not the field  
presenting/selecting the list of choices.

> **···**
>
> On Tue, Nov 17, 2015 at 10:10 PM, Ayub wrote:
> 
> > Mitch,
> > 
> > I tired with little extended version of the form but pulldata() stoppped  
> > working in 2nd/nested repeat group (paths should have been relative i  
> > guess). Is there any example form that I could look into which uses similar  
> > concepts like relative XPath and current() that would be great help.
> > 
> > I've searched into ODK Community group, but couldn't find any specific  
> > answers to it.
> > 
> > Thanks for the help!
> > 
> > ## --
> > 
> > Post: [opendatakit@googlegroups.com](mailto:opendatakit@googlegroups.com)  
> > Unsubscribe: [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com)  
> > Options: [http://groups.google.com/group/opendatakit?hl=en](http://groups.google.com/group/opendatakit?hl=en)
> > 
> > * * *
> > 
> > You received this message because you are subscribed to the Google Groups  
> > "ODK Community" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [opendatakit+unsubscribe@googlegroups.com](mailto:opendatakit+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Mitch Sundt  
> Software Engineer  
> University of Washington  
> [mitchellsundt@gmail.com](mailto:mitchellsundt@gmail.com)
