Math Operation in Embedded Data | XM Community
Skip to main content

Hi,
The pictures below are my embedded data and the related questionnaire. q://QID1448/ChoiceTextEntryValue is the number that participant will input in question "Test 1". q://QID1449/ChoiceTextEntryValue is the number that participant will input in Question "Test 3".
"Oringinal_Fund" displayed just fine as "10000" in my questionnaire. "StockAmount" is always "10000". "Manual Amount" never displayed in my questionnaire. Could anyone help me figure out the possible issue? I highly appreciate it!
Embedded Data.jpgQuestionnaire.jpg

FYI, I follow the instructions below:
Math OperationsAnd there is a space between all the characters in my math operation.


rzhao3 ,
StockAmount has to be calculated after the block that contains question Test1.
ManualAmount has to be calculated after the block that contains Test3 (Since ManualAmount depends on the value entered in Test3, you can't pipe ManualAmount into the question text of Test3. If your intent is to have it update dynamically, you'll need to use JavaScript).
The above means you would need to break your questions in to multiple blocks using the current approach. However, you could avoid that by replicating the math expressions in the questions themselves.


Thank you TomG for providing a solution along with an explanation on pipe text and blocks! 👏



https://community.qualtrics.com/XMcommunity/discussion/comment/51317#Comment_51317TomG Thank you very much, Tom! You really help me out. May I ask two follow-up questions?
1.I tried to replicate the math expression in Q Test2 and put Q Test1, Test2 in the same block. It shows {Invalid Expression} when I preview Q Test2. Where could the issue come from? Below is my trial.
Q Test1:
Current fund: $${e://Field/Original_Fund}
What percentage (%) of money will you invest in government bonds.

input of q://QID1448
Q Test2:
Fund available in stock market: $ $e{ ( 1 - q://QID1448/ChoiceTextEntryValue / 100 ) * e://Field/Original_Fund

2.For the ManualAmount, your observation completely correct, I want to have it updated dynamically. I cannot realize this function using javascript. Could you please help me diagnose the issue? This is the instruction link I followed:
https://community.qualtrics.com/XMcommunity/discussion/9743/display-math-operation-results-real-time
And here is misy best attempt at javascript under Question Test3 so far:
Qualtrics.SurveyEngine.addOnReady(function()
{

var textInputs = jQuery("#"+this.questionId+" .InputText");

var txtFirstNumberValue ="${q://QID1448/ChoiceTextEntryValue}";

var txtSecondNumberValue = parseInt(textInputs.eq(0).val());


 

textInputs.blur(function() {

var result =(1-parseInt(txtFirstNumberValue)/100) * (1-parseInt(txtSecondNumberValue)/100)*10000 ;

 jQuery("#total").text(result);

});

});
Here is the HTML view of Q Test3:
What is the percentage (%) of your stocks that you want Auto-trading Assistant to trade for you automatically? 



Note: Stock value that youd to trade manually is $
And this is what the preview looks like when I input number at Q Test3:
Q Test3 Preview.jpg
Thanks again.


Leave a Reply