Piping from a ranking, to a ranking - in the same order | XM Community
Solved

Piping from a ranking, to a ranking - in the same order

  • 30 May 2023
  • 6 replies
  • 328 views

Badge +2

Hello,

 

Firstly, I’ve seen many previous posts about this - but none actually have a solution, and are form many years ago - so I thought I’d re-ignite this. 

 

I’d like to take the options and order from a ranking question - and then pipe them into another ranking question, later on in my survey (same options, same order) - but I can not seem to find how to do this. 

Does anyone have some suggestions on how I can do this?

Hope to hear, 

thanks,

Neil 

icon

Best answer by Tom_1842 12 June 2023, 16:19

View original

6 replies

Userlevel 7
Badge +61

Good morning from a cloudy Sweden!

So if I understand correctly, you want to have a ranking option in one place, and then later in the survey show the ranking option again, but now preselected with the choice they made in the first one? 

 

If so, then I actually answered this yesterday here

In short, you need to take the selected choices from the first ranking option, and set the selected choices as “Default option” in the latter. 

I tested it myself yesterday and it works. Not sure if it solves exactly what you are trying to do, but it’s a step in the right direction at least :)

I’m also sure it can be done with JS, but I’ll let the wizards answer that, haha!

 

All the best

-Mattias

 

Badge +2

Hi Mattias, 

 Greetings from a sunny Amsterdam! ☀️

Unfortunately, that didn’t work - it still gives me the original starting order. 

Unless I am setting something wrongly….. 

 

Also - I need the ranking in the next question to still function like a ranking question. I.e. I need to pipe each choice……. Here is a link to a quick screen capture video: https://youtu.be/0LfsxICvEz0

Neil 

 

                                 

Userlevel 7
Badge +61

Hi Mattias, 

 Greetings from a sunny Amsterdam! ☀️

Unfortunately, that didn’t work - it still gives me the original starting order. 

Unless I am setting something wrongly….. 

 

Also - I need the ranking in the next question to still function like a ranking question. I.e. I need to pipe each choice……. Here is a link to a quick screen capture video: https://youtu.be/0LfsxICvEz0

Neil 

 

                                 

So sorry! My mind thought “dropdown” when I read Rank. Yeha I can see that that isn’t working. 

I’ll play around with it a little more and see if I can contribute with anything useful :) 

 

All the best

-Mattias

 

Badge +2

thanks Mattias. 

Userlevel 7
Badge +27

Hi, I dug around a bit and I think there are a couple ways to go about this depending on the format the data needs to be in. The method I was able to put in place saves the rankings to embedded data fields and then uses piped text to display the rank order in a 2nd ranking question. The rank order from the 2nd question is then saved to embedded data fields. The data format will have the rank position as columns instead of the rank items. 

To give it a try, first head to the Survey Flow and create the following Embedded Data fields:

Q1rank1
Q1rank2
Q1rank3
Q1rank4
Q1rank5
Q2rank1
Q2rank2
Q2rank3
Q2rank4
Q2rank5
Q1rankfinal
Q2rankfinal

Then, head over to the Builder and create 2 rank order questions with 5 options set to drag and drop. On the 1st question, add the below to the question's JavaScript. This was adapted from ahmedA's code in this post.

Qualtrics.SurveyEngine.addOnPageSubmit(function(){
var c="";
var x = this.getQuestionContainer().querySelectorAll("li");
for(i=0;i<x.length;i++){
var b = x[i].children[1].innerText;
c += x[i].children[1].innerText + ", ";
Qualtrics.SurveyEngine.setEmbeddedData("Q1rank"+(i+1),b);
}
c=c.slice(0, -2);
Qualtrics.SurveyEngine.setEmbeddedData("Q1rankfinal",c);
});

In the 2nd question, use the 'Edit Multiple' to set the answer options with the below:

${e://Field/Q1rank1}
${e://Field/Q1rank2}
${e://Field/Q1rank3}
${e://Field/Q1rank4}
${e://Field/Q1rank5}

Finally, add the below to the 2nd question's JavaScript:

Qualtrics.SurveyEngine.addOnPageSubmit(function(){
var c="";
var x = this.getQuestionContainer().querySelectorAll("li");
for(i=0;i<x.length;i++){
var b = x[i].children[1].innerText;
c += x[i].children[1].innerText + ", ";
Qualtrics.SurveyEngine.setEmbeddedData("Q2rank"+(i+1),b);
}
c=c.slice(0, -2);
Qualtrics.SurveyEngine.setEmbeddedData("Q2rankfinal",c);
});

--

To carry forward rank ordering where the data is in the default format so that each column is an item and the values are the rank position, TomG recommends in this post:

"If you use a Drag and Drop, you'll need to use JavaScript to put the choices in rank order. Pipe all the choices and ranks into your follow-up question, then rearrange the choices based on the ranks.

You can avoid JavaScript if you use a Text Box Rank Order question and set the default answers to the ranks in the first question."

TomG also has a custom function in that post that might assist there.

For JavaScript that uses the rankings of the 1st question to set the initial order of the rankings for the 2nd question, TomG has some code together in this stackoverflow post that does this but for sliders. The approach would be similar for another ranking question though I think, where the rankings from the 1st are piped into an array, sorted, and then the sorting is used to append the choices 1 at a time to the 2nd question in that order.

Badge +2

@Tom, thank you very much for the detailed response and testing. It’s much appreciated. 

Neil 

Leave a Reply