Counter for answers | XM Community
Solved

Counter for answers


Userlevel 2
Badge +10

Hello everyone,
I've recently had the need to set a counter in a Ad Hoc Employee Research Survey to count how many times the same answer was selected.
The survey has questions that can be answered yes, N/A or no and I have the necessity to count how many times yes is selected.
I've tried using embedded data and branch if in the survey flow:
setting the counter "total of yes" and then adding a branch for every question in wich if yes was selected the counter went up.
I was wondering if there were a simplier way to accomplish this.

Thank you in advance 😊

icon

Best answer by bgooldfed 18 May 2022, 04:09

View original

3 replies

Userlevel 5
Badge +25

Hi gaiadm_,
You could add some code to each question with the "Yes" option with something like this
if("${q://QID1/ChoiceGroup/SelectedChoices}" == "Yes") {
var counter = "${e://Field/Counter}";
Qualtrics.SurveyEngine.setEmbeddedData("Counter", count + 1);
}
Of course replace "QID1" with the relevant ID for that question :)
Good luck!

Userlevel 2
Badge +10

Thank you bgooldfed ! This definitely helps. I was wondering if there was a chance to do the same thing without having to set a condition for every question.
You've been very helpful.
Have a good one ☺️

Userlevel 5
Badge +25

Not that I am aware. If you have all of your questions on a single page, I suppose you could use jQuery to find the IDs of all the multiple choice questions and iterate through each one with a single condition. However if they are on separate pages that won't be possible (because the HTML elements are destroyed as the user moves between pages).
If you just want to save yourself from working on multiple code blocks, you could probably just put all of the conditions in your final question block. But you will still need to have a condition for each question you want to check.

Leave a Reply