# Conditional array (numbers)

4 years 11 months ago #81793 by tfj
tfj created the topic: Conditional array (numbers)
I'm sure this has been asked before, but I have not had luck with my search. If someone could provide a link, I would appreciate it.

We have several 12-month and 30-day questions, using the Array (Numbers) question type. By logic, if someone answers that they did something for all 12 of the past 12 months, they would have had to do that something for at least 1 of the last 30 days. Right now, the 30-day question's answer always goes from 0 to 30, regardless of how many months was answered before.

Here is a clarifying example:

A person answers that they smoked for 12 months out of the past 12 months.
In the next question, they are asked, "How many days in the last 30 days did you smoke?" They have the option of 0 to 30, whereas, in reality, the option should be 1 to 30. If they had answered 11 out of 12 months, then the answer choices for 30 days would be 0 to 30.

I am using 1.92+, build 120608.

Is there a simple way to accomplish this?

tfj

4 years 11 months ago #81794 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
Use an expression in the min_num_value_n field. Examples using that option are seen here .

So, min_num_value_n value would be (assuming your question about # of months smoked in the last year is called "monthsSmoked")
`if(monthsSmoked==12,1,0)`

and max_num_value_n would be
`30`

4 years 11 months ago #81801 by Mazi
Mazi replied the topic: Conditional array (numbers)

Thanks!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

4 years 11 months ago #81807 by tfj
tfj replied the topic: Conditional array (numbers)
I have looked through the documentation, reviewed the example surveys for Expression Manager, clicked on the "Expression Manager" in LimeSurvey and poked around, and all but hopped on one foot (lol). So far, I have not seen where "min_num_value_n" is for my array (numbers) question. I am missing the most fundamental piece -- how do I get to the screen that displays this so that I can enter the condition for my question?

I think if I had this one piece, I could be on my way to learning this new feature.

Thanks!

tfj

4 years 11 months ago #81819 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
Edit the question, click on "Show advanced settings". min_num_value_n is labeled "Minimum value". max_num_value_n is labeled "Maximum value". Both are in the "Input" section of the advanced settings

4 years 11 months ago #81823 by tfj
tfj replied the topic: Conditional array (numbers)
I figured it might be that, but I was taking the label literally. My first shot at it didn't work, but I will keep at it until it does, now that I know I was in the right location.

Thanks!

tfj

4 years 11 months ago #81824 by Mazi
Mazi replied the topic: Conditional array (numbers)
See...

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
##### Attachments:

4 years 11 months ago #81826 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
Try this.

#### File Attachment:

File Name: limesurvey..._675.lsg
File Size:7 KB
##### Attachments:

4 years 11 months ago #81845 by tfj
tfj replied the topic: Conditional array (numbers)
Thank you (and Mazi) for your support.

I am still having no luck, although I tried to pattern a couple of test questions as closely as possible to the example you provided. When I run the Survey Logic file, I get the error message that the variable is undefined. This is referring to the question code of the previous question.

Here are some of the things I have tried, through trial-and-error:

1) Changed the questions from Array (Numbers) type to Numerical Input type, as in your example. That didn't work, so I changed them back to Array (Numbers), as in my original.

2) Shortened the question codes from my original, to match the length of your question codes. (My original was made up of 5 characters, which I didn't think would make a difference).

To explain, I have a larger multiple choice question at the head of a series of question, that, through a series of conditions, cause the following questions to appear or not. The examples I made up for your review are from the series of many of the following questions. If the person selects in the larger question that they smoked, for example, the 12-month and the 30-day questions appear.

We have been using this survey (with annual modifications) for about three years with no unsolvable issues. Since I am up against a deadline (for this fiscal year's modifications), I may have to resort to simply adding a warning to the help message. I am hoping, though, to figure this out.

I have attached my example that I made up, for your review. My guess is that you will see something glaringly obvious.

Thanks!

tfj
##### Attachments:

4 years 11 months ago #81870 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
I wasn't able to import your .lsg file - it said it was improperly formatted.

Did the group I attached work for you? If not, there is something funny going on with your install.

If my group did work, please either attach a copy of the survey, or a screen-shot of the Show Logic File report that shows the question with the error, and the question(s) it is trying to refer to.

4 years 11 months ago #81880 by tfj
tfj replied the topic: Conditional array (numbers)
Please find the simple 4-question survey I made up attached. The first two questions are yours. The second 2 questions are mine (in a separate group).

If I had to guess what I am missing, it is that, in your questions, you have to hit the submit button after the first question in order to register it. This would make sense, but since we have quite a few questions, it would be tedious for the survey taker to have to hit the "submit" button after each 12-month question. Maybe this means that I won't be able to use this feature in the manner I would like. At any rate, I am not sure why the Survey Logic file is flagging my 12-month question code as "undefined."

Thanks!

tfj
##### Attachments:

4 years 11 months ago #81895 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
Column 2 of the Survey Logic File shows the variable names for each question and sub-question. Since you are using Array Numbers, it gets a little tricker, since the name is the sq name, followed by an underscore, followed by the answer name. So, since you using a 1x1 array numbers matrix (presumably so that you can use the pick list of numbers), the variable name for "In the 12 months before you entered this treatment program ... " is s12_1_1, so your equation should be:
`if(s12_1_1 == 12,1,0)`

BUT, one last problem - we can't generate the list of drop-down options dynamically, so you can't use equations for min/max values in array numbers unless you use the text input option. And, if you use that option, you might as well use multiple numeric input instead of array(numbers).

4 years 11 months ago #81897 by TMSWhite
TMSWhite replied the topic: Conditional array (numbers)
Actually, there is a way to skin this cat. See attached.

#### File Attachment:

File Name: limesurvey...7521.lss
File Size:31 KB

It uses static value for your min/max (0-30), but uses the new Sub-Question Validation Feature to implement this validation rule:
`this >= if(s12_1_1 == 12, 1, 0)`

Here is a screen shot of smoking less than 12 months:

And if you change to 12 months:

And now the corrected values:

##### Attachments:

4 years 11 months ago #81964 by tfj
tfj replied the topic: Conditional array (numbers)
I greatly appreciate your time in helping me figure this out. I wanted to keep trying it on my own until I had it fixed, so that I could learn this feature better, but my results are different from yours, even though I tried to copy your solution as closely as possible.

The problem is that the tip message appears in the 30-day question even before anything is selected in the 12 month question.

Attached are screen shots of:

1) The relevant section of my survey logic file
2) The two questions I tried your approach on. I have many more to go, but wanted to test it first.

I figure you will take a quick look at this and see the problem right away, but it is eluding me.

Thanks!

tfj