Create sum of several matrix questions | XM Community
Skip to main content

Hi there!
I have a matrix question with 5 items and I just want to create some kind of index out of the 6 statements but it does not work. Not even this simple version (later it will be more complex but not even this "easy" version is working).
It should not be that hard but I just don't get it :(
Already tried many variations...

var brandindex= "";
brandindex=
("${q://QID122_1//SelectedAnswer/Recode/1}"-1)+
("${q://QID122_2//SelectedAnswer/Recode/2}"-1)+
("${q://QID122_3//SelectedAnswer/Recode/3}"-1)+
("${q://QID122_4//SelectedAnswer/Recode/4}"-1)+
("${q://QID122_5//SelectedAnswer/Recode/5}"-1)+
("${q://QID122_6//SelectedAnswer/Recode/6}"-1)
Qualtrics.SurveyEngin/ChoiceNumericEntryValuee.setEmbeddedData( "brandindex", brandindex);
The result is -6, so it ignores the Variables
Thank you for your support!!!
Cheers,
Christine

one more question: is it possible to change the "category" of a question posted here? I posted this question in another category by accident and was not able to change it. So sorry that it's posted twice

For starters, you need to convert the strings to numbers. For example:

parseInt("${q://QID122_1//SelectedAnswer/Recode/1}")


Hi there, you might also be able to make use of Formula Variable Creation in the Data & Analysis tab or Math Operations in the Survey Flow.
https://www.qualtrics.com/support/survey-platform/data-and-analysis-module/data/add-new-fields/formula-variable-creation/
https://www.qualtrics.com/support/survey-platform/survey-module/editing-questions/piped-text/math-operations/


Thanks to both of you!!!!
@TomG: I already thried "parseINT" but it did not work. I thinkt that I might not use the right way to adress the values of a matrix question?
${q://QID122/SelectedAnswerRecode/1}
as piped text works completely fine but if I even use just one variable for my index I just get -1; so the matrix question is ignored 😞
brandindex=parseInt(("${q://QID122//SelectedAnswerRecode/1}")-1)
If you see my mistake please let me know :-)

Tom_1842 : I tried your options too 🙂 Thank you! But my problem is that I need to calulate on basis of the newly built variables as well (my formula is a little more complex so I need several steps). That's why I would prefer using Javascirpt 🙂.


Ah okay, JavaScript may be the way to go here, but Math Operations can also use newly built variables in calculations. If you create each variable in a separate Embedded Data element, the subsequent elements can reference any of the variables defined in the preceding elements.
MathOperations_Multiple.png


TiBa ,
Your parens are incorrect. It should be:
brandindex=parseInt("${q://QID122//SelectedAnswerRecode/1}")-1
Also, just in case, in order to pipe the values, the script must be on a page after the matrix question.


TomG : True, thanks! with the right parens it worked 🙂 Now I have all formulas in my javascript :-)
Tom_1842 Thank you too! I was not aware how much you can actually do with the embedded data! But as I need some conditions in my formulas in this case javascript code is "better to read". But it is still another work which I might use more often :-)


Leave a Reply