Skip to main content
Kinetic Community

Average Score Calculation

How to use Javascript to either display the Average Score or to set an Answer to an Overall Satisfaction Question based on the Average Score.

Description

Recently we received a call from a Customer who wanted to display an Overall Average Score to the end user as they are populating a Survey.  The Customer explained that they had a Customer Satisfaction Survey where the end user would populate the following 6 Radio button questions (Very Satisfied - Very Dissatisfied):

The speed in which your call was answered.

The tone, politeness, and professionalism of the agent.

The communication and language skills of the agent.

The technical support, advice & guidance of the agent.

How well you were kept up to date on the status.

Overall satisfaction with the agent.

The Customer stated that they have had a number of Surveys where the first five questions were populated with Very Satisfied but the Overall satisfaction question was set to Dissatisfied or some lower scoring answer.  Therefore the Customer wanted to automatically answer the Overall satisfaction question with the Average of the first five questions.  The reason was because the Service Desk staff was being graded based on the Survey results and it was "unfair" that all but the Overall satisfaction question was scored with a good "result".

In order to accomplish this functionality I built the Average Score Calculation Survey.  This Survey is attached to this posting.  In this Survey I have added two new Sections.  The first new Section is called Hidden - Workflow.  This section contains Questions Q1 - 5 Score.  These Questions are populated via Set Fields Internal Events attached to the Questions listed above.  The second section is called Score.  This section contains one Question called Average Score.  The Average Score Question is populated via JavaScript in the Custom Header Content.  The JavaScript also populates the Overall satisfaction question using a Switch Statement.  The JavaScript in the Custom Header Content is listed below:

 

<script type="text/javascript">

//This function is used to calculated the average score based on the values selected in the Survey.  Very Satisfied = 5, Satisfied = 4, Neutral = 3 Dissatisfied = 2, and Very Dissatisfied = 1.
//When the questions are answered an Event will push the Score (1-5) into the Q1-5 Score questions.  The Q1-5 Score questions are used in order to calculate the
//averageScore.  Then using KD.utils.Action.setQuestionValue averageScore is pushed into an Average Score question.  The Average Score question can either
//be displayed to the end user or not depending on your business needs.
//The Switch Statement uses the averageScore and then based on the results populates the "Overall satisfaction with the agent." Question.

function averageScore() {

     var q1Score = parseInt(KD.utils.Action.getQuestionValue('Q1 Score'));
     if (!(q1Score)) {
         var q1Score = 0;

     }
     var q2Score = parseInt(KD.utils.Action.getQuestionValue('Q2 Score'));
     if (!(q2Score)) {
         var q2Score = 0;

     }
     var q3Score = parseInt(KD.utils.Action.getQuestionValue('Q3 Score'));
     if (!(q3Score)) {
         var q3Score = 0;

     }
     var q4Score = parseInt(KD.utils.Action.getQuestionValue('Q4 Score'));
     if (!(q4Score)) {
         var q4Score = 0;

     }
     var q5Score = parseInt(KD.utils.Action.getQuestionValue('Q5 Score'));
     if (!(q5Score)) {
         var q5Score = 0;

     }


     var averageScore = Math.round((q1Score + q2Score + q3Score + q4Score + q5Score)/5);

     KD.utils.Action.setQuestionValue('Average Score', averageScore);


switch(averageScore)
{
case 0:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Very Dissatisfied");
     break;
case 1:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Very Dissatisfied");
     break;
case 2:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Dissatisfied");
     break;
case 3:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Neutral");
     break;
case 4:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Satisfied");
     break;
case 5:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Very Satisfied");
     break;
default:
     KD.utils.Action.setQuestionValue('Overall satisfaction with the agent.', "Very Dissatisfied");

}


}

</script>

I have also set the Overall satisfaction question, the Hidden - Workflow Section, and the Score Sections as Read Only.  Note that the Hidden - Workflow Section would be Removed and depending on your business needs you may set the Score Section to Removed too.