Validating single select question

Hello team, i am having a problem validating a couple of single select question.

I have 3 questions

Q1. How many full time employees do you have?

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. More than 5

Q2. How many part time employees do you have?

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. More than 5

Q3 How many employees reside in the camp?

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. More than 5

I want to sum up the number of Q1 and Q2 such that if answer in Q1 and Q2 is 1 and 1, you cannot select option 3 or 4 in Q3. How can i achieve this?

You should filter the answer options for Q3. You can input the syntax into the field found under Filter in the question.

To get the filter to disable option 3 or 4 in Q3 if Q1 and Q2 is both 1, you would use this syntax:

// Disable option 3 and 4 if q1 and q2 is both option 1
(q1==1 && q2==1 && !@optioncode.InList(3,4))||
// Show all if q1 or q2 is not option 1
q1>1 || 
q2>1

However, I think the filter you suggested for Q3 is not strong enough. If Q1 and Q2 is both option 1, then you would also not want the interviewer to select option 5 and 6 as well since they are both also greater than the total number of employees. In general, it seems you would want Q3 to be less than or equal to Q1 + Q2. To achieve that, you would use this syntax:
@optioncode <= q1 + q2

I would also consider situations when there are no employees of a particular type. Such as no part timers. At the moment it is enforced by the categories provided that there is at least one of every type.

@sergiy what do we do when a particular category of employee is not there? Kindly help

Hello @l2nguyen It has worked partly, assuming that all the type of employees are there

How about including a ZERO or NONE category?

That is what i have done , thought there is a way to exclude the zero and still work

Yes, Q1 and Q2 have to be answered for Q3 to have any answer options. If there is a possibility that Q1 or Q2 is skipped, I would suggest writing it this way:
@optioncode <= (q1 ?? 0) + (q2 ?? 0)

?? is called a null-coalescing operator and returns the value on the left hand side if it is not null and the value on the right hand side if it is null. This is very useful for questions that may be skipped when writing enabling or validation conditions.

q1 ?? 0 syntax means that the value of q1 will be used if the question is answered and 0 if the question was skipped (so q1 is null).

For option ZERO or NONE, you can set the option code to be 0 for that same code to the code to still work.

This is exactly what I meant. I can’t envision what possible syntax problem could have scared @simon_mbai away from doing this.

The use of ?? has just been discussed in this forum:

See also here:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator

By removing this answer from the choice set???

Thanks @l2nguyen. This will help