Lengthy Math Operation | XM Community
Skip to main content

I have to calculate the average using three questions which i can do using embedded data like below.

$e{ (q://QID1/SelectedChoicesRecode + q://QID2/SelectedChoicesRecode + q://QID3/SelectedChoicesRecode)/3 }

But the tricky this is that if at any of the question recode value is 6 then we need to remove that from calculation from both numerator and denominator.
We can do this by setting up if conditions in survey flow but here i have given example of just three questions.

In actual i have a list of questions where i have to apply this logic, so is there any suggestion to handle this in easy and tidy way.
Might be if we can able to use IF in the Math operation only.
 

@Salim Qualtrics NO code/drag&drop things is friendly to everyone but it’s gonna bloat up with complex condition like yours. So the solution is YES code if you want it to be tidy, easy to customize( like copy/paste a line of JavaScript instead of drag a element and screen scroll at the same time to find the proper spot).
Also Scoring is a feature to consider here, you can just ignore the 6th value from your formula Scoring (qualtrics.com)
Hope this helps.


@Salim Qualtrics NO code/drag&drop things is friendly to everyone but it’s gonna bloat up with complex condition like yours. So the solution is YES code if you want it to be tidy, easy to customize( like copy/paste a line of JavaScript instead of drag a element and screen scroll at the same time to find the proper spot).
Also Scoring is a feature to consider here, you can just ignore the 6th value from your formula Scoring (qualtrics.com)
Hope this helps.

Thanks for you inputs, that's what i was also thinking.

However, i am trying to set a embedded data like below but i m getting error of {Invalid Expression}.
DO1, DO3 and DO5 are embedded data which i have already set before the below line in survey flow. Any suggestion on why i am getting this error?

$e{ ( ${ e://Field/DO1 }  +  ${ e://Field/DO3 } + ${ e://Field/DO5 } )/ ( ${ e://Field/count }) }


I tried below as well but it’s not working.

 

$e{ $e{ $e{ e://Field/DO1 } + $e{ e://Field/DO3 } + $e{ e://Field/DO5 } }/$e{ e://Field/count } }


 

FYI...Solution

 

$e{ ( ${e://Field/DO1} + ${e://Field/DO3} + ${e://Field/DO5} ) /${e://Field/count} }


I tried below as well but it’s not working.

$e{ $e{ $e{ e://Field/DO1 } + $e{ e://Field/DO3 } + $e{ e://Field/DO5 } }/$e{ e://Field/count } }

Oh I replied to your other post, you don’t need that much $e{ } and need additional spacing in the equation


I tried below as well but it’s not working.

$e{ $e{ $e{ e://Field/DO1 } + $e{ e://Field/DO3 } + $e{ e://Field/DO5 } }/$e{ e://Field/count } }

Oh I replied to your other post, you don’t need that much $e{ } and need additional spacing in the equation

Thanks 😀


FYI...Solution

$e{ ( ${e://Field/DO1} + ${e://Field/DO3} + ${e://Field/DO5} ) /${e://Field/count} }

@Salim Keep in mind if the piped text does not have a value (for example, if the respondent skipped the question the piped text is referencing) and if $ and {  } have not been removed, the equation will fail. Remove $ and {  } from all equations to prevent failures when the piped text is empty.
The failproff equation is $e{ ( e://Field/DO1 + e://Field/DO3 + e://Field/DO5 ) / e://Field/count } like what I replied to your other post.


FYI...Solution

$e{ ( ${e://Field/DO1} + ${e://Field/DO3} + ${e://Field/DO5} ) /${e://Field/count} }

@Salim Keep in mind if the piped text does not have a value (for example, if the respondent skipped the question the piped text is referencing) and if $ and {  } have not been removed, the equation will fail. Remove $ and {  } from all equations to prevent failures when the piped text is empty.
The failproff equation is $e{ ( e://Field/DO1 + e://Field/DO3 + e://Field/DO5 ) / e://Field/count } like what I replied to your other post.

Thanks for pointing this out, i will do as suggested by you.

But i am confused that when to use ${ } and when not. It will be of great help if you can clarify it please.


FYI...Solution

$e{ ( ${e://Field/DO1} + ${e://Field/DO3} + ${e://Field/DO5} ) /${e://Field/count} }

@Salim Keep in mind if the piped text does not have a value (for example, if the respondent skipped the question the piped text is referencing) and if $ and {  } have not been removed, the equation will fail. Remove $ and {  } from all equations to prevent failures when the piped text is empty.
The failproff equation is $e{ ( e://Field/DO1 + e://Field/DO3 + e://Field/DO5 ) / e://Field/count } like what I replied to your other post.

Thanks for pointing this out, i will do as suggested by you.

But i am confused that when to use ${ } and when not. It will be of great help if you can clarify it please.

@Salim It can still work with ${ } but If some how the respondent can skip question and make DO1 or 3 or 5 empty then your equation will be error. So remove ${ } and the equation will work at any condition.


Leave a Reply