Make matrix statements dependent on prior selection | XM Community
Solved

Make matrix statements dependent on prior selection

  • 26 October 2018
  • 15 replies
  • 147 views

Badge
I have a list of managers and the employees that work under them, and I’m trying to set up my survey so that:
• On page 1, managers will select their own name from a dropdown list
• On page 2, there will be a matrix question where the “statements” will be a list of that specific manager’s employees’ names, so that the manager will have to give a response to the same question for each of their employees all on the same page

I currently have all of this info (employee name and the name of the manager they work for) in a spreadsheet, but there’s 100 managers in the study so I’m trying to avoid having to create 100 separate questions and just using simple display logic if possible. Any help would be greatly appreciated!
icon

Best answer by TomG 26 October 2018, 20:14

View original

15 replies

Hello @teammiele ,

We can add all the employees in the matrix question and then add display logic on each of the Statements (Link for choice display logic)
Badge
Hello @Shashi , thanks for the reply, but there's over 1000 employees total so doing that much manual work is not ideal. I'm hoping for a way that is less tedious, maybe using javascript or loop and merge. Really anything that is less tedious and less likely to produce human errors in the design process.
Userlevel 7
Badge +27
An alternative that I think will be easier to implement because you won't have to add display logic for every single employee...

Arrange a copy of your spreadsheet data so that you have one row per manager with the managers in the same order as your drop-down question. Put the manager name in the first column followed by a column for each of their employees. You'll have as many columns as the maximum number of employees per manager + 1 (for the manager).

Put your employee matrix question inside a block by itself and make it a loop & merge block based on the selected answer in your manager drop down (it will only loop once). Highlight and copy all the employees in your spreadsheet (starting at the top of column 2), and paste them into the cell immediately under Field2 in your loop & merge setup.

Pipe the loop & merge fields as the rows of your matrix...${lm://Field/2}, ${lm://Field/3}, etc. up to the maximum number of employees per manager. Add display logic to each row to display only if the loop & merge field is not empty.

You should add employee1, employee2, etc. embedded data fields up to the max number of employees per manager in your survey flow. Then update the embedded data fields in a JavaScript attached to your matrix question with the loop & merge fields.
```
Qualtrics.SurveyEngine.setEmbeddedData("employee1", "${lm://Field/2}");
Qualtrics.SurveyEngine.setEmbeddedData("employee2", "${lm://Field/3}");
etc.
```
Badge
Hi @TomG . Thanks so much, this seems to work almost perfectly. The only thing I'm having trouble with is "Add[ing] display logic to each row to display only if the loop & merge field is not empty." When I go into Display Logic for the rows and try to set it up based on "Loop & Merge," I'm not seeing an option to display based on whether or not the loop & merge field is empty, only an option to display based on whether "Is Current Loop" or "Is Not Current Loop." Am I doing something wrong?

Also, is you suggestion to add employee1, etc. embedded data fields just for better record keeping or is that required to make the rest of this setup run properly?

Thanks again!
Userlevel 7
Badge +27
> @teammiele said:
> The only thing I'm having trouble with is "Add[ing] display logic to each row to display only if the loop & merge field is not empty." When I go into Display Logic for the rows and try to set it up based on "Loop & Merge," I'm not seeing an option to display based on whether or not the loop & merge field is empty, only an option to display based on whether "Is Current Loop" or "Is Not Current Loop." Am I doing something wrong?

Sorry, I forgot about that. Add a descriptive text question before the matrix followed by a page break. Add the following JS (which will take care of setting your embedded data too!):
```
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId).hide();
Qualtrics.SurveyEngine.setEmbeddedData("employee1", "${lm://Field/2}".trim());
Qualtrics.SurveyEngine.setEmbeddedData("employee2", "${lm://Field/3}".trim());
etc...
this.clickNextButton();
});
```
Then use employee1, employee2, etc. in your display conditions for the matrix.

> Also, is you suggestion to add employee1, etc. embedded data fields just for better record keeping or is that required to make the rest of this setup run properly?

Originally, I was thinking just for record keeping. You will have a answers columns 1 through the max number of employees per manager. The embedded variables will tell you who the employees are for each column. However, because of the above, it turns out you need those variables to make the setup work anyway.
Badge
@TomG . Thanks so much; works perfectly!
@TomG I'm working on a similar project (only displaying the employees who directly report to each manager) and am trying to replicate this coding. I have it all down except I can't figure out the adding display conditions to rows piece - can you let me know how to craft the display conditions? I'm not sure if it should be a loop & merge condition, embedded data condition, etc. I'm guessing the "is equal to part" will be "employee1", "employee2" etc. as you mentioned. Thank you in advance!!
Userlevel 7
Badge +27
> @alliequaltrics said:
> @TomG I'm working on a similar project (only displaying the employees who directly report to each manager) and am trying to replicate this coding. I have it all down except I can't figure out the adding display conditions to rows piece - can you let me know how to craft the display conditions? I'm not sure if it should be a loop & merge condition, embedded data condition, etc. I'm guessing the "is equal to part" will be "employee1", "employee2" etc. as you mentioned. Thank you in advance!!

See the second post I made on this thread above. The matrix rows can be the piped embedded variables, employee1, employee2, etc. and the display conditions are "if embedded data employee1 is not empty", etc.
That worked perfectly - thank you so much!
> The matrix rows can be the piped embedded variables, employee1, employee2, etc. and the display conditions are "if embedded data employee1 is not empty", etc.

@TomG sorry to bump an old post, but I'm wondering if there is a faster way to add the display conditions to each row? In the OP there were 1000s of rows in the matrix. I don't have anywhere near that number, but adding the logic row by row is arduous.
Userlevel 7
Badge +27
> @tarensanders said:
> > The matrix rows can be the piped embedded variables, employee1, employee2, etc. and the display conditions are "if embedded data employee1 is not empty", etc.
>
> @TomG sorry to bump an old post, but I'm wondering if there is a faster way to add the display conditions to each row? In the OP there were 1000s of rows in the matrix. I don't have anywhere near that number, but adding the logic row by row is arduous.

In the solution above the number of rows in the matrix is the maximum number of employees per manager (e.g., if any manager has max of 20 direct reports, there would be 20 rows in the matrix).

Anyway, there isn’t a shortcut for adding display logic to matrix statements.
Thanks, Tom. In my case one of the respondents had >50 respondents and thought that might have been the case for the OP as well. Appreciate the help.
Badge

I am following this process for a slightly different project. Please describe what it means to “Pipe the loop and merge fields”. Thank you.

Badge +5

@TomG Hi TomG, I came across with the same scenario. 
The solution you have shared will work only 1 iteration of loop, what we need to do for more than 1 iteration.

issue is :
1. I have a matrix Question including 20 rows (coming from sample file) and 2 columns (involved and not involved). On the basis of this question (projects qualified as “involved”) we are running few questions in loop. 
2. Matrix Question in loop, where we need to pipe products (as rows in matrix question) associated with each project (we have 50 products in sample file).
Please suggest.

Userlevel 7
Badge +27

@TomG Hi TomG, I came across with the same scenario. 
The solution you have shared will work only 1 iteration of loop, what we need to do for more than 1 iteration.

issue is :
1. I have a matrix Question including 20 rows (coming from sample file) and 2 columns (involved and not involved). On the basis of this question (projects qualified as “involved”) we are running few questions in loop. 
2. Matrix Question in loop, where we need to pipe products (as rows in matrix question) associated with each project (we have 50 products in sample file).
Please suggest.

Base the loop & merge off a multi-select question instead of a single-select (dropdown) question. Your embedded data fields (employee1, etc. in the example above) will be temporary (only apply to the current loop).

Leave a Reply