Creating a new variable that counts the values of another embedded variable | XM Community
Skip to main content

Creating a new variable that counts the values of another embedded variable

  • September 21, 2022
  • 7 replies
  • 409 views

Forum|alt.badge.img+2

Hi! Pardon me if this has been asked before. I perused the forums and didn't find anything.
I've launched an intercept survey on our website using Website/App Feedback. The intercept is using JavaScript to embed a multi-value variable, which I'm passing into the survey in the survey flow. For the sake of explanation, let's say this variable is fruit, and fruit can have one or more values.
I am wanting to create a new variable that counts how many fruits are embedded in each response. Let's call it fruit_count. So, if for a given response fruit = "orange", fruit_count should equal 1. If fruit = 'banana, strawberry', fruit_count should equal 2, and so on.
Does anyone know a way to achieve this? The field editor in the Data Analysis tab looked promising, but was a dead end.
Thanks! Grateful for the support in this community.

7 replies

MSobotta
Level 4 ●●●●
Forum|alt.badge.img+25
  • Level 4 ●●●●
  • September 21, 2022

What kind of intercept is it? If it's a Custom HTML survey inserted you could have some creative survey logic in the flow which would count it behind the scenes using a bunch of if statements by looking through each fruit individually. You just keep a counter and increment it every time you find a fruit. If you aren't using Customer HTML or something Non-guided where you can't use survey logic I am at a loss short of doing it manually after the fact.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • September 21, 2022

You could do it in the survey with JS added to a question all respondents see. Add fruit_count as an embedded data field at the beginning of the survey flow. Then this JS to a question:
Qualtrics.SurveyEngine.addOnload(function() {
var fcount = "{e://Field/fruit}".split(", ").length;
Qualtrics.SurveyEngine.setEmbeddedData("fruit_count",fcount);
});


Forum|alt.badge.img+2
  • Author
  • September 22, 2022

Thank you so much, MSobotta and TomG . The survey is just a pop-over, so not using Custom HTML.
TomG I deployed this JavaScript but it's returning

1
for each response. I'm playing around with it to see if I can get it working, but also open to ideas.
Thanks again for your kind help!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • September 22, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/49868#Comment_49868The split string is probably wrong. I used comma+space because that is what you posted and how Qualtrics delimits multiple answers. Maybe the delimiter is just a comma.


MSobotta
Level 4 ●●●●
Forum|alt.badge.img+25
  • Level 4 ●●●●
  • September 22, 2022

That being said you would have to make sure you are not off by one.


Forum|alt.badge.img+2
  • Author
  • September 23, 2022

Forum|alt.badge.img+2
  • Author
  • September 23, 2022