I am trying this to identify a person based on responses of kind of occupation done in past 1 yr, and identify him based on responses:
Q1 (Multiple choice) Occupation(s) in past 1 year
Options:
Unemployed (xml value = 1)
Worked on daily wages in unorganized sector (xml value = 2)
Worked on salary in unorganized sector (xml value = 3)
Worked in organized sector (xml value = 4)
Ran business (xml value = 5)
Q2 (calculate) if(${occupation}=1 or ${occupation}=2,YES,NO) {cal_identify}
Q3 (note) Person had regular source of income: ${cal_identify}
So if a person selects either 1 or 2 or both, then it should become ‘Yes’ otherwise ‘No’, but it is not working.
I tried this but even if the wrong combination of options are used, it is giving response as true. I am not able to select the person only if option 1 and /or 2 is selected. If either of the option is selected with options 3 to 5, then the person is not eligible.
@peeyush, maybe you could refer to this post discussed previously, which should give you a clue of how to handle if condition for a select-multiple question.
And what if option 2 is selected with 3 or 4 or even option 5? Does that too go at No?
First of all my apology that I made typo error in my describing my problem posted above, kindly read the corrected description as:
I am trying this to identify a person based on responses of kind of occupation done in past 1 yr, and identify him based on responses:
Q1 (Multiple choice) Occupation(s) in past 1 year
Options:
Unemployed (xml value = 1)
Worked on daily wages in unorganized sector (xml value = 2)
Worked on salary in unorganized sector (xml value = 3)
Worked in organized sector (xml value = 4)
Ran business (xml value = 5)
Q2 (calculate) if(${occupation}=1 or ${occupation}=2,NO,YES) {cal_identify}
Q3 (note) Person had regular source of income: ${cal_identify}
So if a person selects either 1 or 2 or both, then it should become ‘No’ otherwise ‘Yes’, but it is not working.
Desired output in Q3 should be ‘No’ when only 1 or only 2 or both 1 & 2 are selected. For all other combinations the desired output should be ‘Yes’ . In the above spreadsheet, I am partially successful with Trial 1 but when both 1 & 2 are chosen then it doesn’t work.
I tried this but it is not giving desired output for combinations other than specified above.
I find that both if() and selected() can work if ‘or’ and ‘and’ could be used together, but the documentation tells they can’t be used together in single calculate question.
Ok, I now understood, that 3, 4, 5 will dominate a combination with 1 or 2.
So, you may try
if( selected(${occupation}, ‘3’) or selected(${occupation}, ‘4’) or selected(${occupation}, ‘5’), ‘YES’, if(selected(${occupation}, ‘’), ‘’, ‘NO’) ).
I also added an empty result, if nothing is selected (yet).
or and and can be combined, but not inside the same (bracket) level. You may need to put them in bracket parts with brackets, e.g if( (${a} = 1 or ${a} = 2) and (${b} = ‘4’ or ${b} = ‘5’), … , … )
FormLogicError: Could not evaluate: if((selected( /model/instance[1]/aNK7vtgBn6A3LAHkNu7Pnn/occupation ,1,2 and selected ( /model/instance[1]/aNK7vtgBn6A3LAHkNu7Pnn/occupation ,!=3,!=4,!=5))=‘TRUE’,‘NO’,‘YES’), message: Cannot read properties of undefined (reading ‘toString’)
but I get the idea, I am trying to make it correct, if it works will share here.
I don’t have any error message in KoBo Preview, in Validator (Preview), FormBuilder or in KoBo deploy. Maybe you used " instead of 2 single '?
You don’t need three steps.
Side-note: A person might also have other “regular source of income”, e,g, student grant, humanitarian aid, social aid from government aid, remittances from family members/friends, pension. Also, being paid on daily basis, sometimes can be a rather “regular” income/working condition. And, (self-employed) “business”, like street hawker, can mean a rather irregular income.
On side note: The above mentioned condition was an example of similar problem I was facing while while drafting a form with different set of questions, so the complete logic of questions is not shared here.