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

Calculate Average from sum and also take into account when fields are blank.

Community Beginner ,
Aug 22, 2023 Aug 22, 2023

Hello everyone, 

I need help with an Adobe Form. I'm pretty new to Adobe, so please be kind. 

I have created an Performance Evaluation Form for work, with different sections, each section has a total sum. Now I need to calculate an average rating of that total. (see below)

Rebecca28543448lfax_0-1692716237743.png

As you can see the calculation is not correct, 57/ 36 = 1.58 NOT 1.76! 

Also, I need to account if we only have 33 fields filled instead of 36. So account for "0" or blank fields.

This is the code I got from someone. I'm not sure why is not working. (see below)

 

var pG = this.getField("SUPERVISOR PRIOR YR SKILLS GOAL #34").value;
var RT = this.getField("RATING TOTAL").value;

var fAR = ((RT/36));
var hAR = ((RT/33));


if (pG == 0) event.value=((hAR));
else event.value=((fAR));

 

If anyone could, please help!

TOPICS
JavaScript , PDF forms
835
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 ,
Aug 22, 2023 Aug 22, 2023

Hi there, anyone see a mistake in the code posted?

 

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 ,
Aug 22, 2023 Aug 22, 2023

You will need to share the file for help with this, as the code looks fine.

If you want to ignore empty fields you can use a function to go over all the fields you want to add up, and check their values first. If they are not empty, add their value to the total and increment a counter by one.

At the end, divide the total by the counter, if the latter is not zero.

I've posted code that does just that multiple times here. Search the forum for "calcAverage".

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 ,
Aug 22, 2023 Aug 22, 2023

Here is the file, if you think it helps. 

the sum of all the sections are working and adding it up fine..

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 ,
Aug 22, 2023 Aug 22, 2023

Check the JS Console. There are errors in your code.

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 ,
Aug 23, 2023 Aug 23, 2023

Hi, could you be specific about the errors? How do I fix it?

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 ,
Aug 23, 2023 Aug 23, 2023
LATEST

Open the JS Console (Ctrl+J) and you'll see them for yourself.

What I see is this:

TypeError: this.getField("SUPERVISOR PRIOR YR SKILLS GOAL #34") is null
1:Field:Calculate

 

It's possible in your version it will not show the field name, though.

What this means is that you've specified the wrong field name in that line.

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