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

Create sum of several matrix questions

  • May 12, 2022
  • 6 replies
  • 232 views

Forum|alt.badge.img+2

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

6 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • May 13, 2022

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

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


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • May 13, 2022

Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • May 14, 2022

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 :-).


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • May 15, 2022

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


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • May 16, 2022

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.


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • May 17, 2022

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 :-)