Skip to main content
Monteigo99
Inspiring
June 23, 2016
Answered

Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

  • June 23, 2016
  • 1 reply
  • 766 views

Hello,

I have a series of fields that require a yes, no, n/a answer from a drop down. Then I need to auto calculate the # of times 'Yes' is selected divided by the number of Yes's and No's (but excludes adding the na's into the denominator). Numerator=Countif("yes")/Denominator=Countif("yes" or "no").

Thanks

This topic has been closed for replies.
Correct answer try67

OK, then you can use this code as the custom calculation script of the field where you want the result to appear (PC MCKTOTAL):

var totalYes = 0;

var total = 0;

for (var i=1; i<=5; i++) {

    var f = this.getField("PC MCKRow"+i);

    if (f.valueAsString=="Yes") {

        totalYes++;

        total++;

    } else if (f.valueAsString=="No") {

        total++;

    }

}

if (total==0) event.value = "";

else event.value = totalYes / total;

1 reply

try67
Community Expert
Community Expert
June 23, 2016

What are the names of the fields involved?

Monteigo99
Inspiring
June 23, 2016

PC MCKRow1, PC MCKRow2, PC MCKRow3, PC MCKRow4, PC MCKRow5 (Yes, No, NA). PC MCKTOTAL (%)

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 23, 2016

OK, then you can use this code as the custom calculation script of the field where you want the result to appear (PC MCKTOTAL):

var totalYes = 0;

var total = 0;

for (var i=1; i<=5; i++) {

    var f = this.getField("PC MCKRow"+i);

    if (f.valueAsString=="Yes") {

        totalYes++;

        total++;

    } else if (f.valueAsString=="No") {

        total++;

    }

}

if (total==0) event.value = "";

else event.value = totalYes / total;