This article describes how to use a Control Box to select which multi-variable questions to display in a table, chart, or visualization. The post contains the steps required to create a Page like this:
- A data set with at least two multi-variable questions to chose between.
- A Control Box control (see How to Create a Combo Box Filter or How to Create a List Box Filter).
- An output (e.g., tables, chart, visualization) to control.
Additional requirements for Method 1:
- Your variables must be set together as either a Binary – Multi or Numeric – Multi, as applicable.
- All questions you wish to choose between have the same number of variables (answer codes).
- The variable labels should be applicable for all questions, as these can't dynamically change.
Method 1 - chose between questions with the same number of variables
When the requirements for this method are met, you can follow the same process as you would when using a single-response question.
Method 2 - other variables
When the number of variables and/or variable labels are different between the questions you wish to dynamically change using a control box, it is better to substitute the tables instead of questions.
- Go to the Anything menu, and select Page Design > Control > Combo Box (Drop-down).
- With the control selected go to the object inspector > Control > Item List and input the variable set labels you wish to appear in the list (e.g., Gender; Age; Income). All items in the list should be separated by a semi-colon (;).
- Change Selection Mode to Single Selection.
- Change When item lists changes to Select First.
- Still, in the object inspector go to Properties > General > Name and input the desired name (e.g. Question.control.box) to use when referencing the Control Box in the R code.
- Drag and drop questions you wish to show from the Data Sets tree onto the page to create a table. Repeat this step for all the questions you wish to show.
- OPTIONAL: Drag and drop a variable from the Data Sets tree onto the table itself into the Columns field to create a crosstab.
In this example, I have created three crosstabs to chose between:
- Select the tables and select Hide from the menu.
- Go to Calculation > Custom Code.
- Click on the Page where you want to position the output.
- Update and input the below R Code:
if (Question.control.box=="Gender") table.Awareness.by.Gender elseThe above code looks up the selected value in our Control box (e.g. "Gender"), and when matched returns the referenced table. You will need to update the above code and replace Question.control.box with the name of your control (see Step 5). You will also need to replace the mentions of table.Awareness.by.Gender and so on with the names of your tables created in Step 6. To locate the name of the table, select it and go to its object inspector > Properties > GENERAL > Name.
if (Question.control.box=="Age") table.Awareness.by.Age else
if (Question.control.box=="Income") table.Awareness.by.Income
- You can use the Calculation Output you created as the Data source for a visualization or another type of analysis.