Skip to main content
Participant
Feb 10, 2024 9:37 PM UTC
Question

Weighted average calculation

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 is closed to new replies. Start a new post to keep the conversation going.

1 reply

Nesa Nurani
Community Expert
Community Expert
Feb 11, 2024 5:35 PM UTC

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;
Translate