Setting embeded data with javascript and branch it | XM Community
Skip to main content

Hi there.

 

I’m new to Qualtrics and JS.

I want to create an embedded data field named 'max' that calculates the maximum value by comparing the values of other embedded data fields. I've tried to do this as shown in the image, but it's not working for several days now.

I've read several posts suggesting that I should add JavaScript to the question block before the embedded data is executed. I'm not sure if I'm doing it correctly as shown in the image below or if it's enough to just code it in the embedded data section within the survey flow tab.

 

Any help would be appreciated.

 

 

In the image, there are only two embedded data fields, but in reality, I need to create 10 fields and find the maximum value among them. It seems like using simple branching logic won't be sufficient to find the maximum value.

@HelpmePlz You need to add the coding as JavaScript to a question. Math calculations in an embedded data block will not work. You may also want to check if working with scoring makes sense for you.


You entered the wrong text for A1. Math operations require $e{} outside of piped text, add spaces in between and remove the ${} of those piped text. 

For example:

A1= $e{ abs( q://QID2/SelectedChoicesRecode ) + q://QID8/SelectedChoicesRecode }

Refer to Math Operations (qualtrics.com) for more details.

 

You could use multiple branch logic in the survey flow to compare the numbers, but it may be very tedious when the numbers to compare increases. Using branch logic also prevent back button if you enabled back button in the settings.

For example,

Branch 1: If A1 >= A2, then maxvalue=A1.

Branch 2: If A2 > A1, then maxvalue=A2.

Branch 3: If A3>maxvalue, then maxvalue=A3.

Branch 4: If A4>maxvalue, then maxvalue=A4 and so on.


@chackbusch and @Chee Heng_SZ, thanks for offering your perspectives and knowledge. @HelpmePlz, please confirm if either solution works to assist future Community members.


Leave a Reply