Hidden value calculation not working

I have a checklist question with 5 options, with a correct response if
either answer '5' is selected or if answers '1', '2', '3', and '4' are all
selected. My hidden value calculation is the following: if(/data/question =
('1' and '2' and '3' and '4') or '5', 1, 0)

For some reason, it's giving me correct answers no matter what is selected.
What's the problem here?

Thanks!

Hi Eric

You need to use the selected
https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-selected()
function to determine if a multi-select question has a particular option
selected. In you're case I think this should work:

if((selected(/data/question, '1') and selected(/data/question, '2') and
selected(/data/question, '3') and selected(/data/question, '4')) or
selected(/data/question, '5'), 1, 0)

··· On 30 June 2016 at 09:19, Eric Jospe wrote:

I have a checklist question with 5 options, with a correct response if
either answer '5' is selected or if answers '1', '2', '3', and '4' are
all selected. My hidden value calculation is the following: if(/data/question
= ('1' and '2' and '3' and '4') or '5', 1, 0)

For some reason, it's giving me correct answers no matter what is
selected. What's the problem here?

Thanks!

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

--
Simon Kelly
Senior Engineer | Dimagi South Africa

Hey Simon, thanks for your response. I've copied your suggested code and am
now getting a validation error.

This is what I have in the form: if(selected(/data/E/Balanced_meal, '1')
and selected(/data/E/Balanced_meal, '2') and
selected(/data/E/Balanced_meal, '3') and selected(/data/E/Balanced_meal,
'4')) or selected(/data/E/Balanced_meal, '5'), 1, 0)

Resulting in the following error:

Parse error on line 1:

.../Balanced_meal, '5'), 1, 0)
-----------------------^
Expecting 'EOF', 'OR', 'AND', 'EQ', 'NEQ', 'LT', 'LTE', 'GT', 'GTE', 'PLUS', 'MINUS', 'MULT', 'DIV', 'MOD', 'UNION', got 'COMMA'

··· On Thursday, June 30, 2016 at 10:36:43 AM UTC+2, skelly wrote: > > Hi Eric > > You need to use the selected > () > function to determine if a multi-select question has a particular option > selected. In you're case I think this should work: > > if((selected(/data/question, '1') and selected(/data/question, '2') and > selected(/data/question, '3') and selected(/data/question, '4')) or > selected(/data/question, '5'), 1, 0) > > On 30 June 2016 at 09:19, Eric Jospe <eric....@gmail.com > wrote: > >> I have a checklist question with 5 options, with a correct response if >> either answer '5' is selected or if answers '1', '2', '3', and '4' are >> all selected. My hidden value calculation is the following: if(/data/question >> = ('1' and '2' and '3' and '4') or '5', 1, 0) >> >> For some reason, it's giving me correct answers no matter what is >> selected. What's the problem here? >> >> Thanks! >> >> -- >> 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. >> > > > > -- > Simon Kelly > Senior Engineer | Dimagi South Africa >

Hello Eric,

Removing the one extra bracket after '4' should solve the problem.

I will also suggest you an alternative to the solution, you can use:

if(selected(/data/question1, '1') and selected(/data/question1, '2') and
selected(/data/question1, '3') and selected(/data/question1, '4 ') and
not(selected(/data/question1, '5')) or /data/question1 = '5', "1", "0")

I have added the not(selected(data/question1, '5')) so that it does not
give you '1' when all the five options are selected. I also removed the
selected() function after the or as that would be the only value you want
for your other argument.

Hope this works for you.

··· On Thursday, June 30, 2016 at 3:53:37 PM UTC+5:30, Eric Jospe wrote: > > Hey Simon, thanks for your response. I've copied your suggested code and > am now getting a validation error. > > This is what I have in the form: if(selected(/data/E/Balanced_meal, '1') > and selected(/data/E/Balanced_meal, '2') and > selected(/data/E/Balanced_meal, '3') and selected(/data/E/Balanced_meal, > '4')) or selected(/data/E/Balanced_meal, '5'), 1, 0) > > Resulting in the following error: > > Parse error on line 1: > > .../Balanced_meal, '5'), 1, 0) > -----------------------^ > Expecting 'EOF', 'OR', 'AND', 'EQ', 'NEQ', 'LT', 'LTE', 'GT', 'GTE', 'PLUS', 'MINUS', 'MULT', 'DIV', 'MOD', 'UNION', got 'COMMA' > > > > On Thursday, June 30, 2016 at 10:36:43 AM UTC+2, skelly wrote: >> >> Hi Eric >> >> You need to use the selected >> () >> function to determine if a multi-select question has a particular option >> selected. In you're case I think this should work: >> >> if((selected(/data/question, '1') and selected(/data/question, '2') and >> selected(/data/question, '3') and selected(/data/question, '4')) or >> selected(/data/question, '5'), 1, 0) >> >> On 30 June 2016 at 09:19, Eric Jospe wrote: >> >>> I have a checklist question with 5 options, with a correct response if >>> either answer '5' is selected or if answers '1', '2', '3', and '4' are >>> all selected. My hidden value calculation is the following: if(/data/question >>> = ('1' and '2' and '3' and '4') or '5', 1, 0) >>> >>> For some reason, it's giving me correct answers no matter what is >>> selected. What's the problem here? >>> >>> Thanks! >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Simon Kelly >> Senior Engineer | Dimagi South Africa >> >

Thanks, Kishan! That worked well.

··· On Thursday, June 30, 2016 at 12:41:08 PM UTC+2, Kishan Sampat wrote: > > Hello Eric, > > Removing the one extra bracket after '4' should solve the problem. > > I will also suggest you an alternative to the solution, you can use: > > if(selected(/data/question1, '1') and selected(/data/question1, '2') and > selected(/data/question1, '3') and selected(/data/question1, '4 ') and > not(selected(/data/question1, '5')) or /data/question1 = '5', "1", "0") > > I have added the not(selected(data/question1, '5')) so that it does not > give you '1' when all the five options are selected. I also removed the > selected() function after the or as that would be the only value you want > for your other argument. > > Hope this works for you. > > On Thursday, June 30, 2016 at 3:53:37 PM UTC+5:30, Eric Jospe wrote: >> >> Hey Simon, thanks for your response. I've copied your suggested code and >> am now getting a validation error. >> >> This is what I have in the form: if(selected(/data/E/Balanced_meal, '1') >> and selected(/data/E/Balanced_meal, '2') and >> selected(/data/E/Balanced_meal, '3') and selected(/data/E/Balanced_meal, >> '4')) or selected(/data/E/Balanced_meal, '5'), 1, 0) >> >> Resulting in the following error: >> >> Parse error on line 1: >> >> .../Balanced_meal, '5'), 1, 0) >> -----------------------^ >> Expecting 'EOF', 'OR', 'AND', 'EQ', 'NEQ', 'LT', 'LTE', 'GT', 'GTE', 'PLUS', 'MINUS', 'MULT', 'DIV', 'MOD', 'UNION', got 'COMMA' >> >> >> >> On Thursday, June 30, 2016 at 10:36:43 AM UTC+2, skelly wrote: >>> >>> Hi Eric >>> >>> You need to use the selected >>> () >>> function to determine if a multi-select question has a particular option >>> selected. In you're case I think this should work: >>> >>> if((selected(/data/question, '1') and selected(/data/question, '2') and >>> selected(/data/question, '3') and selected(/data/question, '4')) or >>> selected(/data/question, '5'), 1, 0) >>> >>> On 30 June 2016 at 09:19, Eric Jospe wrote: >>> >>>> I have a checklist question with 5 options, with a correct response if >>>> either answer '5' is selected or if answers '1', '2', '3', and '4' are >>>> all selected. My hidden value calculation is the following: if(/data/question >>>> = ('1' and '2' and '3' and '4') or '5', 1, 0) >>>> >>>> For some reason, it's giving me correct answers no matter what is >>>> selected. What's the problem here? >>>> >>>> Thanks! >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Simon Kelly >>> Senior Engineer | Dimagi South Africa >>> >>