Referencing data from the (n-1)th repeat group

Hi CommCare users,

A repeat group question that's perplexing me a bit--I've spent a really
long time playing around with this in conjunction with the Repeat Groups
CommCare Help page but there's still something that's eluding me.

We use a repeat group to ask some information about each child in a
household, based on previously entered data about how many children there
are total. (So the group repeats as many times as there are children.)

We are interested in calculating birth spacing between each successive
child. In other words, in each group, we would like there to be a hidden
calculation that subtracts Child X's birthday from Child (X-1)'s birthday.
(Does that make sense?).

I know how to reference previously entered data using the count() function,
but the problem is that I'm not referencing a specific child in the repeat
group (as in, I won't always be referencing Child 2), rather, I'm
referencing the immediately previously entered child.

Any tips on how to make this work? Is it even possible?

Thanks,
Sarah

Greetings Sarah,

Sorry it's taken so long to get back to you. I've been tinkering to see if
there is a good way to support this workflow. Unfortunately at the moment,
this functionality is not very well supported.

One workaround could be to build this app out without using repeats. This
scenario is somewhat limiting in that you'll need to choose an upper limit
for how many children you can register. Suppose it's unlikely that any
family will have more than 20 children. In that case you'd make 20
question groups all with the same questions. In order to support the birth
spacing question, you could simply take the question which captures age
from each previous question group and subtract it from the question which
captures age in the current group.

In order to make the groups display properly, you'd simply make the display
condition for each group something like

/data/number_children >= 1
/data/number_children >= 2

And so on.

Of course, this solution breaks down if the user surpasses the upper limit
of children groups provided (so in the example above, if you've only made
20 groups to capture data on children, nothing would be captured about the
21st child). So you'll want to choose an upper limit which you know is
unlikely to be surpassed.

Hopefully, you'll find this solution helpful.

Cheers,
Mike

··· 2016-02-17 10:01 GMT-07:00 Sarah S. :

Hi CommCare users,

A repeat group question that's perplexing me a bit--I've spent a really
long time playing around with this in conjunction with the Repeat Groups
CommCare Help page but there's still something that's eluding me.

We use a repeat group to ask some information about each child in a
household, based on previously entered data about how many children there
are total. (So the group repeats as many times as there are children.)

We are interested in calculating birth spacing between each successive
child. In other words, in each group, we would like there to be a hidden
calculation that subtracts Child X's birthday from Child (X-1)'s birthday.
(Does that make sense?).

I know how to reference previously entered data using the count()
function, but the problem is that I'm not referencing a specific child in
the repeat group (as in, I won't always be referencing Child 2), rather,
I'm referencing the immediately previously entered child.

Any tips on how to make this work? Is it even possible?

Thanks,
Sarah

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Michael O'Donnell | Project Manager | Dimagi Inc.

585 Massachusetts Ave
Suite 3
Cambridge MA 02139
*United States: *1 (973) 819 8763
*Skype: *michael.o.donnell6

Hey Sarah,

I think this might be possible with repeats as well.

  • Create a hidden value outside of the repeat called repeat_dobs
  • Set the calculation for prev_dobs to be: join(' ', /data/my_repeat/dob)
  • Inside the repeat, add a hidden value called age_difference
  • Set the calculation for age_difference to be: if(position(..) > 0 and
    count-selected(/data/repeat_dobs) > position(..),
    /data/household_member/dob - date(selected-at(/data/repeat_dobs,
    position(..) - 1)), '')

The hidden value repeat_dobs keeps a list of all the entered dates of birth
in the repeat
The hidden value age_difference uses the position(..) function to figure
out exactly which repeat its in. If its in the first repeat, there is no
age difference and it sets the value to blank. If its in a later repeat,
it goes to the list in repeat_dobs and grabs the previous one.

Thanks,
Sheel

··· On Wed, Feb 24, 2016 at 10:32 PM, Michael O'Donnell wrote:

Greetings Sarah,

Sorry it's taken so long to get back to you. I've been tinkering to see
if there is a good way to support this workflow. Unfortunately at the
moment, this functionality is not very well supported.

One workaround could be to build this app out without using repeats. This
scenario is somewhat limiting in that you'll need to choose an upper limit
for how many children you can register. Suppose it's unlikely that any
family will have more than 20 children. In that case you'd make 20
question groups all with the same questions. In order to support the birth
spacing question, you could simply take the question which captures age
from each previous question group and subtract it from the question which
captures age in the current group.

In order to make the groups display properly, you'd simply make the
display condition for each group something like

/data/number_children >= 1
/data/number_children >= 2

And so on.

Of course, this solution breaks down if the user surpasses the upper limit
of children groups provided (so in the example above, if you've only made
20 groups to capture data on children, nothing would be captured about the
21st child). So you'll want to choose an upper limit which you know is
unlikely to be surpassed.

Hopefully, you'll find this solution helpful.

Cheers,
Mike

2016-02-17 10:01 GMT-07:00 Sarah S. searle.sarah@gmail.com:

Hi CommCare users,

A repeat group question that's perplexing me a bit--I've spent a really
long time playing around with this in conjunction with the Repeat Groups
CommCare Help page but there's still something that's eluding me.

We use a repeat group to ask some information about each child in a
household, based on previously entered data about how many children there
are total. (So the group repeats as many times as there are children.)

We are interested in calculating birth spacing between each successive
child. In other words, in each group, we would like there to be a hidden
calculation that subtracts Child X's birthday from Child (X-1)'s birthday.
(Does that make sense?).

I know how to reference previously entered data using the count()
function, but the problem is that I'm not referencing a specific child in
the repeat group (as in, I won't always be referencing Child 2), rather,
I'm referencing the immediately previously entered child.

Any tips on how to make this work? Is it even possible?

Thanks,
Sarah

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Michael O'Donnell | Project Manager | Dimagi Inc.

585 Massachusetts Ave
Suite 3
Cambridge MA 02139
*United States: *1 (973) 819 8763
*Skype: *michael.o.donnell6

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah