Using multiple 'if' statements

Is it possible to use multiple IF statements to assign more than 2 values
to a hidden value property, like in Excel? I have a multiple choice
question with 4 possible responses. In Excel, I would write the following
formula:

IF(Q1=1,“A1”,IF(Q1=2,“A2”,IF(Q1=3,“A3”,“A4”)))

Is this possible in CommCare? I’d also be interested in doing this with a
checkbox question.

Clarification: this seems to work fine with 3 IF statements, but not any
more. Is there a limit to the number of IF statements CommCare will accept?

··· On Tuesday, August 23, 2016 at 2:51:40 PM UTC+2, Eric Jospe wrote: > > Is it possible to use multiple IF statements to assign more than 2 values > to a hidden value property, like in Excel? I have a multiple choice > question with 4 possible responses. In Excel, I would write the following > formula: > > IF(Q1=1,"A1",IF(Q1=2,"A2",IF(Q1=3,"A3","A4"))) > > Is this possible in CommCare? I'd also be interested in doing this with a > checkbox question. > >

Hi Eric,

There is no limit I am aware of - what error are you running into? When
troubleshooting complex if statements I sometimes use a text editor like
Notepad ++ or Sublime Text so I can more easily see if there is an issue
with matching parentheses.

Jeremy

··· On Tue, Aug 23, 2016 at 7:03 PM, Eric Jospe wrote:

Clarification: this seems to work fine with 3 IF statements, but not any
more. Is there a limit to the number of IF statements CommCare will accept?

On Tuesday, August 23, 2016 at 2:51:40 PM UTC+2, Eric Jospe wrote:

Is it possible to use multiple IF statements to assign more than 2 values
to a hidden value property, like in Excel? I have a multiple choice
question with 4 possible responses. In Excel, I would write the following
formula:

IF(Q1=1,“A1”,IF(Q1=2,“A2”,IF(Q1=3,“A3”,“A4”)))

Is this possible in CommCare? I’d also be interested in doing this with a
checkbox question.


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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.

Hey Jeremy, here’s the error message I’m getting:

Build Failed!

  • Validation Error: Problem with bind for /data/A/land_problems_case
    contains invalid calculate expression [if(/data/A/Land_problems_explained =
    ‘Too_small’, “Ubutaka ni buto cyane”, if(/data/A/Land_problems_explained =
    ‘Stones’, “Ubutaka bwuzuye amabuye/amakoro cyangwa ntibwera”,
    if(/data/A/Land_problems_explained = ‘Far’, “Ubutaka burengerwa n’amazi”,
    “Ubutaka buri kure y’urugo”, “Ibindi”)))] if() function requires 3
    arguments but 4 are present. in form Baseline / Home Visit 1
    https://www.commcarehq.org/a/gardens-for-health/apps/view/2b6a814be0d3904b8f7c4d059bb26b3c/modules-2/forms-0/
    in
    module “Baseline & Home Visits”

-Eric

··· On Tue, Aug 23, 2016 at 3:38 PM, Jeremy W. wrote:

Hi Eric,

There is no limit I am aware of - what error are you running into? When
troubleshooting complex if statements I sometimes use a text editor like
Notepad ++ or Sublime Text so I can more easily see if there is an issue
with matching parentheses.

Jeremy

On Tue, Aug 23, 2016 at 7:03 PM, Eric Jospe eric.jospe@gmail.com wrote:

Clarification: this seems to work fine with 3 IF statements, but not any
more. Is there a limit to the number of IF statements CommCare will accept?

On Tuesday, August 23, 2016 at 2:51:40 PM UTC+2, Eric Jospe wrote:

Is it possible to use multiple IF statements to assign more than 2
values to a hidden value property, like in Excel? I have a multiple choice
question with 4 possible responses. In Excel, I would write the following
formula:

IF(Q1=1,“A1”,IF(Q1=2,“A2”,IF(Q1=3,“A3”,“A4”)))

Is this possible in CommCare? I’d also be interested in doing this with
a checkbox question.


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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.


You received this message because you are subscribed to a topic in the
Google Groups “commcare-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/commcare-users/ol2Tu7wCSPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Eric, the error is because your last if statement has 4 arguments
instead of 3 (there are 2 “else” expressions):

if(/data/A/Land_problems_explained = ‘Far’, “Ubutaka burengerwa n’amazi”,
“Ubutaka buri kure y’urugo”, “Ibindi”)

If you want to include “Ibindi” as an alternative you would need another if
statement to distinguish between that and the prior value.

Jeremy

··· On Tue, Aug 23, 2016 at 7:44 PM, Eric Jospe wrote:

Hey Jeremy, here’s the error message I’m getting:

Build Failed!

  • Validation Error: Problem with bind for /data/A/land_problems_case
    contains invalid calculate expression [if(/data/A/Land_problems_explained
    = ‘Too_small’, “Ubutaka ni buto cyane”, if(/data/A/Land_problems_explained
    = ‘Stones’, “Ubutaka bwuzuye amabuye/amakoro cyangwa ntibwera”,
    if(/data/A/Land_problems_explained = ‘Far’, “Ubutaka burengerwa
    n’amazi”, “Ubutaka buri kure y’urugo”, “Ibindi”)))] if() function requires
    3 arguments but 4 are present. in form Baseline / Home Visit 1
    https://www.commcarehq.org/a/gardens-for-health/apps/view/2b6a814be0d3904b8f7c4d059bb26b3c/modules-2/forms-0/ in
    module “Baseline & Home Visits”

-Eric

On Tue, Aug 23, 2016 at 3:38 PM, Jeremy W. jwacksman@dimagi.com wrote:

Hi Eric,

There is no limit I am aware of - what error are you running into? When
troubleshooting complex if statements I sometimes use a text editor like
Notepad ++ or Sublime Text so I can more easily see if there is an issue
with matching parentheses.

Jeremy

On Tue, Aug 23, 2016 at 7:03 PM, Eric Jospe eric.jospe@gmail.com wrote:

Clarification: this seems to work fine with 3 IF statements, but not any
more. Is there a limit to the number of IF statements CommCare will accept?

On Tuesday, August 23, 2016 at 2:51:40 PM UTC+2, Eric Jospe wrote:

Is it possible to use multiple IF statements to assign more than 2
values to a hidden value property, like in Excel? I have a multiple choice
question with 4 possible responses. In Excel, I would write the following
formula:

IF(Q1=1,“A1”,IF(Q1=2,“A2”,IF(Q1=3,“A3”,“A4”)))

Is this possible in CommCare? I’d also be interested in doing this with
a checkbox question.


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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.


You received this message because you are subscribed to a topic in the
Google Groups “commcare-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/commcare-users/ol2Tu7wCSPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.

Got it, thank you!

-Eric

··· On Tue, Aug 23, 2016 at 4:18 PM, Jeremy W. wrote:

Hi Eric, the error is because your last if statement has 4 arguments
instead of 3 (there are 2 “else” expressions):

if(/data/A/Land_problems_explained = ‘Far’, “Ubutaka burengerwa n’amazi”,
“Ubutaka buri kure y’urugo”, “Ibindi”)

If you want to include “Ibindi” as an alternative you would need another
if statement to distinguish between that and the prior value.

Jeremy

On Tue, Aug 23, 2016 at 7:44 PM, Eric Jospe eric.jospe@gmail.com wrote:

Hey Jeremy, here’s the error message I’m getting:

Build Failed!

  • Validation Error: Problem with bind for /data/A/land_problems_case
    contains invalid calculate expression [if(/data/A/Land_problems_explained
    = ‘Too_small’, “Ubutaka ni buto cyane”, if(/data/A/Land_problems_explained
    = ‘Stones’, “Ubutaka bwuzuye amabuye/amakoro cyangwa ntibwera”,
    if(/data/A/Land_problems_explained = ‘Far’, “Ubutaka burengerwa
    n’amazi”, “Ubutaka buri kure y’urugo”, “Ibindi”)))] if() function requires
    3 arguments but 4 are present. in form Baseline / Home Visit 1
    https://www.commcarehq.org/a/gardens-for-health/apps/view/2b6a814be0d3904b8f7c4d059bb26b3c/modules-2/forms-0/ in
    module “Baseline & Home Visits”

-Eric

On Tue, Aug 23, 2016 at 3:38 PM, Jeremy W. jwacksman@dimagi.com wrote:

Hi Eric,

There is no limit I am aware of - what error are you running into? When
troubleshooting complex if statements I sometimes use a text editor like
Notepad ++ or Sublime Text so I can more easily see if there is an issue
with matching parentheses.

Jeremy

On Tue, Aug 23, 2016 at 7:03 PM, Eric Jospe eric.jospe@gmail.com wrote:

Clarification: this seems to work fine with 3 IF statements, but not
any more. Is there a limit to the number of IF statements CommCare will
accept?

On Tuesday, August 23, 2016 at 2:51:40 PM UTC+2, Eric Jospe wrote:

Is it possible to use multiple IF statements to assign more than 2
values to a hidden value property, like in Excel? I have a multiple choice
question with 4 possible responses. In Excel, I would write the following
formula:

IF(Q1=1,“A1”,IF(Q1=2,“A2”,IF(Q1=3,“A3”,“A4”)))

Is this possible in CommCare? I’d also be interested in doing this
with a checkbox question.


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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.


You received this message because you are subscribed to a topic in the
Google Groups “commcare-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/commcare-users/ol2Tu7wCSPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@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.


Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.


You received this message because you are subscribed to a topic in the
Google Groups “commcare-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/commcare-users/ol2Tu7wCSPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.