Using min() function outside of a repeat group with filtered answer choices

Hi all,

If the structure of my survey is:

children_information (repeat group)

children_informationlist (question list)

ChildName

ChildLiving

[other questions]

ChildAge (question list)

calc_alivedays

calc_alivemonths

calc_aliveyears

____endrepeat

calc_under5children

And I want to find:

  1. Name of the youngest child alive under 5
  2. Name of the youngest child

I've tried the calculate conditions below none have worked so far. I keep
getting an error message, stating that I've typed an accidental ' at the
beginning of the expression. I've reported this issue, but I'm looking for
help to ensure that I have the right code.

  1. calc_youngestunder5 [ with display condition: calc_under5children > 0
    ]
  • children_informationlist [min(
    #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivedays
    )][min(
    #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivemonths
    )][min(
    #form/hsld_section/children_information/children_informationlist/ChildAge/calc_aliveyears
    )]/ChildName[0]

  • children_informationlist [min(ChildAge/calc_alivedays)]
    [min(ChildAge/calc_alivemonths)]
    [min(ChildAge/calc_aliveyears)]/ChildName[0]

  • separate hidden values calculating the minimum of days, years, months
    work... however not within the calculate condition for one and two above

    • min_days =
      min(#form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivedays
    • min_months = min(
      #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivemonths)
    • min_years =
      min(#form/hsld_section/children_information/children_informationlist/ChildAge/calc_aliveyears )
    • children_informationlist [min_days] [min_months]
      [min_years]/ChildName[0]
    1. calc_youngestchild : same equations as above, just without the
      display condition

I'm sure I'm interpreting something wrong or am missing something small,
but I would genuinely appreciate any help!

Cheers,

Staci

Hi Staci,

A few ideas:

  • I'd definitely recommend breaking out the min_days, min_months, and
    min_years calculations into separate values so that they're easier to
    debug. You can these put these values in output values
    https://confluence.dimagi.com/display/commcarepublic/Hidden+Values+Tutorial+Part+4:+Displaying+an+Output
    so
    that they're easier to debug.
  • Your filter expressions (between the '') currently do not evaluate
    to a truth statement but an integer so these will not work. When using
    filters the expressions between should be "True for the node I want to
    select, false for others" - so in this case you'd want EG:
  • #form/hsld_section/children_informationlist [calc_alivedays =
    #form/min_days]

This says "select the iteration where its calc_alivedays is equal to the
minimum of all the calc_alivedays" - note that we have to use #form before
min_days since this is a value not belonging to the repeated node

  • I'm also a bit confused by the days/months/years logic - is
    calc_alivedays the total number of days the child has been alive? If so
    then the months and years calculations should be redundant.

Hope this helps.

Cheers,
Will

··· On Tue, Dec 20, 2016 at 9:44 AM, Staci Leigh wrote:

Hi all,

If the structure of my survey is:

children_information (repeat group)

children_informationlist (question list)

ChildName

ChildLiving

[other questions]

ChildAge (question list)

calc_alivedays

calc_alivemonths

calc_aliveyears

____endrepeat

calc_under5children

And I want to find:

  1. Name of the youngest child alive under 5
  2. Name of the youngest child

I've tried the calculate conditions below none have worked so far. I keep
getting an error message, stating that I've typed an accidental ' at the
beginning of the expression. I've reported this issue, but I'm looking for
help to ensure that I have the right code.

  1. calc_youngestunder5 [ with display condition: calc_under5children >
    0 ]
  • children_informationlist [min( #form/hsld_section/
    children_information/children_informationlist/ChildAge/calc_alivedays
    )][min( #form/hsld_section/children_information/children_
    informationlist/ChildAge/calc_alivemonths )][min( #form/hsld_section/
    children_information/children_informationlist/ChildAge/calc_aliveyears
    )]/ChildName[0]

  • children_informationlist [min(ChildAge/calc_alivedays)]
    [min(ChildAge/calc_alivemonths)] [min(ChildAge/calc_aliveyears)
    ]/ChildName[0]

  • separate hidden values calculating the minimum of days, years,
    months work... however not within the calculate condition for one and two
    above

    • min_days = min(#form/hsld_section/children_information/children_
      informationlist/ChildAge/calc_alivedays
    • min_months = min( #form/hsld_section/
      children_information/children_informationlist/ChildAge/calc_
      alivemonths)
    • min_years = min(#form/hsld_section/children_information/children_
      informationlist/ChildAge/calc_aliveyears )
    • children_informationlist [min_days] [min_months]
      [min_years]/ChildName[0]
    1. calc_youngestchild : same equations as above, just without the
      display condition

I'm sure I'm interpreting something wrong or am missing something small,
but I would genuinely appreciate any help!

Cheers,

Staci

--
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.

Hi Will,

Thank you for your response. You are correct, I only need to use min(days)
for this expression. Age is recorded in days if the child is under 1 month,
months if under 2 years, or years otherwise.

I've now tried :

#form/hsld_section/children_information/children_informationlist[calc_alivedays
= #form/hsld_section/calc_mindays]/ChildName[0]

#form/hsld_section/children_information/children_informationlist[ChildAge/calc_alivedays
= #form/hsld_section/calc_mindays]/ChildName[0]

Even when deleting the hidden value and trying again, I still find this
error:

https://lh3.googleusercontent.com/-5b1BDQI7iYQ/WFlwd6FVWLI/AAAAAAAAAk8/DKx5RwXGzjgeiYx1v2-YNLDiyrcNXZMcgCLcB/s1600/error.png

Any further advice?

Cheers,

Staci

··· On Tuesday, December 20, 2016 at 6:40:50 PM UTC+3, William Pride wrote: > > Hi Staci, > > A few ideas: > > - I'd definitely recommend breaking out the min_days, min_months, and > min_years calculations into separate values so that they're easier to > debug. You can these put these values in output values > so > that they're easier to debug. > - Your filter expressions (between the '[ ]') currently do not > evaluate to a truth statement but an integer so these will not work. When > using filters the expressions between should be "True for the node I want > to select, false for others" - so in this case you'd want EG: >> >> - #form/hsld_section/children_informationlist [calc_alivedays = >> #form/min_days] >> > This says "select the iteration where its calc_alivedays is equal to > the minimum of all the calc_alivedays" - note that we have to use #form > before min_days since this is a value not belonging to the repeated node > - I'm also a bit confused by the days/months/years logic - is > calc_alivedays the total number of days the child has been alive? If so > then the months and years calculations should be redundant. > > Hope this helps. > > Cheers, > Will > > On Tue, Dec 20, 2016 at 9:44 AM, Staci Leigh <staci.su...@gmail.com > wrote: > >> Hi all, >> >> If the structure of my survey is: >> >> children_information (repeat group) >> >> children_informationlist (question list) >> >> ChildName >> >> ChildLiving >> >> [other questions] >> >> ChildAge (question list) >> >> calc_alivedays >> >> calc_alivemonths >> >> calc_aliveyears >> >> ____endrepeat >> >> calc_under5children >> >> >> >> And I want to find: >> >> 1. Name of the youngest child alive under 5 >> 2. Name of the youngest child >> >> >> I've tried the calculate conditions below none have worked so far. I keep >> getting an error message, stating that I've typed an accidental ' at the >> beginning of the expression. I've reported this issue, but I'm looking for >> help to ensure that I have the right code. >> >> 1. calc_youngestunder5 [ with display condition: calc_under5children >> > 0 ] >> >> >> - children_informationlist [min( >> #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivedays >> )][min( >> #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivemonths >> )][min( >> #form/hsld_section/children_information/children_informationlist/ChildAge/calc_aliveyears >> )]/ChildName[0] >> - children_informationlist [min(ChildAge/calc_alivedays)] >> [min(ChildAge/calc_alivemonths)] >> [min(ChildAge/calc_aliveyears)]/ChildName[0] >> - separate hidden values calculating the minimum of days, years, >> months work... however not within the calculate condition for one and two >> above >> - min_days = >> min(#form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivedays >> - min_months = min( >> #form/hsld_section/children_information/children_informationlist/ChildAge/calc_alivemonths) >> - min_years = >> min(#form/hsld_section/children_information/children_informationlist/ChildAge/calc_aliveyears ) >> - children_informationlist [min_days] [min_months] >> [min_years]/ChildName[0] >> >> 2. calc_youngestchild : same equations as above, just without >> the display condition >> >> I'm sure I'm interpreting something wrong or am missing something small, >> but I would genuinely appreciate any help! >> >> Cheers, >> >> Staci >> >> >> >> >> >> >> >> >> >> -- >> 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-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >

Staci,

Apologies, looks like this construct isn't yet supported for easy references
https://confluence.dimagi.com/display/commcarepublic/Easy+References+FAQ
in form builder. I'll email you offline with details and a workaround.

Cheers,
Will

··· On Tue, Dec 20, 2016 at 1:01 PM, Staci Leigh wrote:

Hi Will,

Thank you for your response. You are correct, I only need to use min(days)
for this expression. Age is recorded in days if the child is under 1 month,
months if under 2 years, or years otherwise.

I've now tried :

#form/hsld_section/children_information/children_informationlist[calc_alivedays
= #form/hsld_section/calc_mindays]/ChildName[0]

#form/hsld_section/children_information/children_informationlist[ChildAge/calc_alivedays
= #form/hsld_section/calc_mindays]/ChildName[0]

Even when deleting the hidden value and trying again, I still find this
error:

https://lh3.googleusercontent.com/-5b1BDQI7iYQ/WFlwd6FVWLI/AAAAAAAAAk8/DKx5RwXGzjgeiYx1v2-YNLDiyrcNXZMcgCLcB/s1600/error.png

Any further advice?

Cheers,

Staci

On Tuesday, December 20, 2016 at 6:40:50 PM UTC+3, William Pride wrote:

Hi Staci,

A few ideas:

  • I'd definitely recommend breaking out the min_days, min_months, and
    min_years calculations into separate values so that they're easier to
    debug. You can these put these values in output values
    https://confluence.dimagi.com/display/commcarepublic/Hidden+Values+Tutorial+Part+4:+Displaying+an+Output so
    that they're easier to debug.
  • Your filter expressions (between the '') currently do not
    evaluate to a truth statement but an integer so these will not work. When
    using filters the expressions between should be "True for the node I want
    to select, false for others" - so in this case you'd want EG:
  • #form/hsld_section/children_informationlist [calc_alivedays =
    #form/min_days]

This says "select the iteration where its calc_alivedays is equal to
the minimum of all the calc_alivedays" - note that we have to use #form
before min_days since this is a value not belonging to the repeated node

  • I'm also a bit confused by the days/months/years logic - is
    calc_alivedays the total number of days the child has been alive? If so
    then the months and years calculations should be redundant.

Hope this helps.

Cheers,
Will

On Tue, Dec 20, 2016 at 9:44 AM, Staci Leigh staci.su...@gmail.com wrote:

Hi all,

If the structure of my survey is:

children_information (repeat group)

children_informationlist (question list)

ChildName

ChildLiving

[other questions]

ChildAge (question list)

calc_alivedays

calc_alivemonths

calc_aliveyears

____endrepeat

calc_under5children

And I want to find:

  1. Name of the youngest child alive under 5
  2. Name of the youngest child

I've tried the calculate conditions below none have worked so far. I
keep getting an error message, stating that I've typed an accidental ' at
the beginning of the expression. I've reported this issue, but I'm looking
for help to ensure that I have the right code.

  1. calc_youngestunder5 [ with display condition: calc_under5children

0 ]

  • children_informationlist [min( #form/hsld_section/child
    ren_information/children_informationlist/ChildAge/calc_alivedays
    )][min( #form/hsld_section/children_information/children_inf
    ormationlist/ChildAge/calc_alivemonths )][min(
    #form/hsld_section/children_information/children_inf
    ormationlist/ChildAge/calc_aliveyears )]/ChildName[0]

  • children_informationlist [min(ChildAge/calc_alivedays)]
    [min(ChildAge/calc_alivemonths)] [min(ChildAge/calc_aliveyears)
    ]/ChildName[0]

  • separate hidden values calculating the minimum of days, years,
    months work... however not within the calculate condition for one and two
    above

    • min_days = min(#form/hsld_section/childre
      n_information/children_informationlist/ChildAge/calc_alivedays
    • min_months = min( #form/hsld_section/childr
      en_information/children_informationlist/ChildAge/calc_alivemonths)
    • min_years = min(#form/hsld_section/childre
      n_information/children_informationlist/ChildAge/calc_aliveyears )
    • children_informationlist [min_days] [min_months]
      [min_years]/ChildName[0]
    1. calc_youngestchild : same equations as above, just without
      the display condition

I'm sure I'm interpreting something wrong or am missing something small,
but I would genuinely appreciate any help!

Cheers,

Staci

--
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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.