Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Jun 23, 2016 Jun 23, 2016

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

TOPICS
Acrobat SDK and JavaScript
698
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 23, 2016 Jun 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;

Translate
Community Expert ,
Jun 23, 2016 Jun 23, 2016

What are the names of the fields involved?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 23, 2016 Jun 23, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2016 Jun 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 23, 2016 Jun 23, 2016

You're Awesome!  Thank you, it worked.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 13, 2016 Jul 13, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2016 Jul 13, 2016

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 14, 2016 Jul 14, 2016
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines