How to calculate the average of fields with values.

New Here ,
May 29, 2019

Copy link to clipboard

Copied

How would I write the formula in adobe?

Message was edited by: Malcolm Thomson

TOPICS
Acrobat SDK and JavaScript

Views

163

Likes

Translate

Translate

Report

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

How to calculate the average of fields with values.

New Here ,
May 29, 2019

Copy link to clipboard

Copied

How would I write the formula in adobe?

Message was edited by: Malcolm Thomson

TOPICS
Acrobat SDK and JavaScript

Views

164

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 29, 2019 0
Most Valuable Participant ,
May 29, 2019

Copy link to clipboard

Copied

So basically you want to ignore empty fields, right? I posted code that does that on these forums. Search for "calcAverage" and you should be able to find it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 29, 2019 0
New Here ,
May 30, 2019

Copy link to clipboard

Copied

I'm brand new to Adobe, so unsure of where to put the script and make it work.  I went into custom script and edit and pasted the script you had written.  also brand new at calculations, so sorry if I sound stupid.

when you say fields in your script, does that mean I put my fields everywhere it says fields?  below are the fields I am looking at

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
Most Valuable Participant ,
May 30, 2019

Copy link to clipboard

Copied

Yes, this code should be used as the custom calculation script of the field where you want to show the result.

You need to enter the names of the fields, between quotes, into the fields array, yes.
Give it a try and post here how it goes... If it's not working correctly press Ctrl+J and check if there are any error messages in the window that opens.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
New Here ,
May 30, 2019

Copy link to clipboard

Copied

this is what I have put in, but it gives me an error for line 2

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
Most Valuable Participant ,
May 30, 2019

Copy link to clipboard

Copied

No, you misunderstood. Leave the function code as-is. Place it as a doc-level script via Tools - JavaScript - Document JavaScripts.

Then as the custom calculation script of your field call it, like this:

calcAverage(["1W1", "1W2", ...], true, true);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
New Here ,
May 30, 2019

Copy link to clipboard

Copied

works awesome.  thanks.

now can I add a different formula for different cells?  this is the formula in excel

=IFERROR(2*(SQRT(((I22+I23)/2*I24*2)/PI())*1000),"")

how would I make that happen in adobe?

Its the average W1, W2, depth fields that would be used instead of the I22, I 23 and I24

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
Most Valuable Participant ,
May 30, 2019

Copy link to clipboard

Copied

You would need to study how to do calculations in Acrobat, and also the JavaScript Math object.

I'm guessing the IFERROR command is used here in case the divisor is 0. You would need to add an if-statement to control for that in the JavaScript code.

Some useful resources:

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

JavaScript Math Object

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
New Here ,
May 30, 2019

Copy link to clipboard

Copied

thanks.  but when I add a new script, does that just get added at the bottom of the first script under tools/javascript/documents

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0
try67 LATEST
Most Valuable Participant ,
May 30, 2019

Copy link to clipboard

Copied

You should not be adding the scripts there. Follow my instructions carefully, please. I never said anything about Document Actions.

Also, this script can be located just under the field. You don't need to put it at the doc-level (the other one also doesn't have to be there, but it's better in case you want to use it in multiple locations).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 30, 2019 0