Correlate calculation to subsequent answer (auto-populate?)

173
4
12-03-2018 08:31 AM
Highlighted
New Contributor II

Hello.

I've got a survey where I'm trying to calculate a numerical risk score and correlate that score to a risk level, e.g. low, moderate & high based on varying scores. Currently I'm able to calculate the score and use relevance to display the risk level on the survey, but I need to use the risk level (low, moderate, high) in reporting and Operations Dashboard.  Is there a way to automatically select an answer to a select one risk level question based on a calculation?  Or any other ways of accomplishing this?

Thanks!

Dave

Reply
0 Kudos
4 Replies
Highlighted
Occasional Contributor II

You could create a text field and use nested "if" statements to calculate the value based on the score.

For example:

if(${riskScore} < 100, "Low", if(${riskScore} < 300, "Moderate", if(${riskScore} >= 300, "High", "None")))

This calculation would set the text value to be "Low" if riskScore is <100, "Moderate" if riskScore is >= 100 and < 300, "High" if riskScore is >= 300, and "None" otherwise (if riskScore is blank, for example).

This thread has more discussion about nested "if" statements:

How to use "if" and "then" on survey 123?

Reply
0 Kudos
Highlighted
New Contributor II

Thanks Stephen!

I had tried that and tried it again after your recommendation.  The error I keep getting says "...XPath evaluation: cannot handle function 'if' requires 3 arguments. Only 2 provided.

 

Any ideas?

Reply
0 Kudos
Highlighted
Occasional Contributor II

That error suggests that one of the three elements of an "if" statement is missing (test condition, return if true, return if false). With how complicated nested ifs can get, it could just be an issue of a missing comma somewhere in the statement.

Reply
0 Kudos
Highlighted
New Contributor II

I finally figured it out!  Here's what I ended up with:

if((${total}>0 and ${total}<=12),"Unlikely",if((${total}>=13 and ${total}<=35),"Low",if((${total}>=36 and ${total}<=45),"Moderate",if(${total}>=46,"High",null))))

Thanks again for your help Stephen!

Reply
0 Kudos