# Conditional array (numbers)

il y a 7 ans 4 mois #81793 par tfj
Conditional array (numbers) a été créé par tfj
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

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners
il y a 7 ans 4 mois #81794 par TMSWhite
Réponse de TMSWhite sur le sujet 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`

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81801 par Mazi
Réponse de Mazi sur le sujet Conditional array (numbers)
...and once you have set this up successfully, please add your example at docs.limesurvey.org/Expression+Manager+E...ples_for_Expressions

Thanks!

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81807 par tfj
Réponse de tfj sur le sujet 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

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81819 par TMSWhite
Réponse de TMSWhite sur le sujet 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

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81823 par tfj
Réponse de tfj sur le sujet 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

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81824 par Mazi
Réponse de Mazi sur le sujet 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
Want to use your survey offline -> www.offlinesurveys.com
##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81826 par TMSWhite
Réponse de TMSWhite sur le sujet Conditional array (numbers)
Try this.

#### Fichier attaché :

Nom du fichier : limesurvey..._675.lsg
Taille du ficher :7 ko
##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81845 par tfj
Réponse de tfj sur le sujet 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
##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81870 par TMSWhite
Réponse de TMSWhite sur le sujet 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.

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81880 par tfj
Réponse de tfj sur le sujet 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
##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81895 par TMSWhite
Réponse de TMSWhite sur le sujet 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).

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81897 par TMSWhite
Réponse de TMSWhite sur le sujet Conditional array (numbers)
Actually, there is a way to skin this cat. See attached.

#### Fichier attaché :

Nom du fichier : limesurvey...7521.lss
Taille du ficher :31 ko

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:

##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81964 par tfj
Réponse de tfj sur le sujet 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
##### Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

il y a 7 ans 4 mois #81967 par TMSWhite
Réponse de TMSWhite sur le sujet Conditional array (numbers)
Looks like you're doing a group-level preview rather than testing the full survey (or your submitted the page, it had an error, and was re-displayed). Group-level preview used to show those validation messages, but we fixed that prior to the 120613 release.

Connexion ou Créer un compte pour participer à la conversation.