Matrix Table: Count of selected choices across a column of statements | XM Community
Skip to main content

Hello,
I haven't found the answer I'm looking for in other posts here so thought I'd try asking myself - I'm trying to grab the count of selections made underneath the column "Active/Contributing Member" in the matrix table pictured below so I can multiply it by a certain value. Trying to do the same for the second column. So if there are three different statements chosen under Active/Contributing Member...., the count should = 3. If 5 are chosen under chair, the count = 5. I need to store these values in two variables so I can access them later in the survey.
Unfortunately the piped text menu option "Selected Choices Count" sums selections across rows, not columns. I essentially need the same thing but for columns. Does anybody have any pointers on how I can do this? My guess is I might be able to add a click counter in the matrix table's javascript but not sure how I'd pass the variables to another page on the survey...
Appreciate your help.

Screen Shot 2021-12-19 at 10.24.58 PM.png

I haven't tested this myself, but you might try the Transpose table option and see if counts sums the selections the way you want after applying that.
image.png


I think you can do it via Javascript. Just pipetext the selected choices for the column then split it then get the length.

sample:
var count = "${q://QID1/ChoiceGroup/SelectedChoicesForAnswer/1}".split(",").length;


Yes below is working fine.
var count = "${q://QID1/ChoiceGroup/SelectedChoicesForAnswer/1}".split(",").length


MatthewM The transposition would have been the easiest solution, but unfortunately I get a 0 for the count, so I don't think it works. Thank you for the suggestion, though!
Sateesh darelS That worked. Thank you.


This is great and exactly what I'm looking for darelS Sateesh avunjian . Apologies for the following question is very basic and demonstrates how much of a noobie I am.
Where is the best place to add the JS creation of this new variable that counts the number of statements chosen for a particular column? Would that during hte UnLoad phase of the same question?
If so, would the full syntax look something like the following?

Qualtrics.SurveyEngine.addOnUnload(function()
{
   /*Place your JavaScript here to run when the page is unloaded*/
   var count_var = "${q://QID1/ChoiceGroup/SelectedChoicesForAnswer/1}".split(",").length

   Qualtrics.SurveyEngine.setEmbeddedData("embedded_var_name", count_var)
});


Leave a Reply