Skip to main content
Participant
February 10, 2024
Question

Weighted average calculation

  • February 10, 2024
  • 1 reply
  • 228 views

I am trying to establish a weighted average calculation where the number of fields that are part of the calculation could vary between 7-10 depending on how many factors get considered.  This is for an employee performance review and we've created checkbox groups for each factor.  This is the formula currently being used but need to adjust so we can use a variable number of factors to be considered per employee:

 

(0.7 * ((Group1 + Group2 + Group3 + Group4 + Group5 + Group6 + Group7 + Group8 + Group9 + Group10) / 10)) + (0.3 * ((Group11 + Group12 + Group13 + Group14 + Group15) /5))

 

Any advice?

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
February 11, 2024

Assuming you added values as checkbox export value, this will calculate average of 0.7*group1-10 + 0.3*average group11-15 but will only average checkboxes that are checked:

var group10 = 0,totalG10 = 0,t1 = 0;
var group5 = 0, totalG5 = 0,t2 = 0;

for(var i=1; i<=15; i++){
 if(i <= 10){
  if(this.getField("Group"+i).valueAsString !== "Off"){
   group10++;
   totalG10 += Number(this.getField("Group"+i).valueAsString);}}
 else{
  if(this.getField("Group"+i).valueAsString !== "Off"){
   group5++;
   totalG5 += Number(this.getField("Group"+i).valueAsString);}}}

if(group10 !== 0)
 t1 = 0.7*(totalG10/group10);
if(group5 !== 0)
 t2 = 0.3*(totalG5/group5);

event.value = t1+t2;