7 Replies Latest reply on Jul 14, 2016 9:41 AM by rustyb2343416

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

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

• ###### 1. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

What are the names of the fields involved?

• ###### 2. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

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

• ###### 3. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

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;
```
• ###### 4. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

You're Awesome!  Thank you, it worked.

• ###### 5. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

I need some help that is similar to this question.

I have 10 drop down boxes with -,yes,no. The boxes are labeled Is salesman Behind on Route_1, Is salesman Behind on Route_2, all the way to 10. Some boxes will have just a - in them.

I need when they click on yes to add 1 and no or - would be 0.

Would it be the same as above? And I know I would need to change the field name.

• ###### 6. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

Yes, very similar... Try this:

```var totalYes = 0;
var total = 0;
for (var i=1; i<=10; i++) {
var f = this.getField("Is salesman Behind on Route_"+i);
if (f.valueAsString=="yes") {
totalYes++;
total++;
} else {
total++;
}
}
if (total==0) event.value = "";
else event.value = totalYes / total;
```
• ###### 7. Re: Custom calc for returning a percentage for number of times 'Yes' is returned in other fields.

Is there a script to have just one box display a percentage from the total sum that I can use?