Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- Acrobat SDK
- Discussions
- Re: Javascript maths calculation (SUM, COUNTIF)

- Re: Javascript maths calculation (SUM, COUNTIF)

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/td-p/12806973
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

Hi, I'm hoping someone can help me urgently on this one...

I have the following formula in excel, but not sure how to change it so it works as Java in the custom calculation field in Acrobat (I've used some online tools but none seem to work).

- =SUM(B2:Q2)/(13*(COUNTIF(B2:Q2,"<>")))*100

JS wise, this where I've got to....not very far:

- event.value = ( this.getField("FINALscoreS1").value + this.getField("FINALscoreS2").value + this.getField("FINALscoreS3").value );

There'll be a number of 'FINALscoreS#' fields (yet to be decided). and what I'm after is:

The sum of all results in the 'FINALscoreS#' fields, divided by the sum of 13*however many 'FINALscoreS#' have a value (even if that value is zero...so ignoring any blanks).

(And then multiplied by 100 to give a percentage - the excel formula works perfectly if that's any use)

Does that makes sense? Can anyone help?? Pretty sure there'll be an array involved somewhere...

Huge thanks in advance...I expect for a JS guru this is as simple as 2+2, apologies!!

🙂

TOPICS

Acrobat SDK and JavaScript
,
Mac
,
Windows

Community guidelines

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

Enthusiast
,
Mar 11, 2022
Mar 11, 2022

Hi,

Try that and let me know if I didn't understand someting.

```
var nb=numberOfFields;
var theSum=0;
var noBlank=0;
for (var i=1; i<=nb; i++) {
theSum+=Number(this.getField("FINALscoreS"+i).value);
if (this.getField("FINALscoreS"+i).valueAsString!="") noBlank++;
}
event.value=theSum*100/(13*noBlank);
```

@+

7
Replies
7

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12807256#M88860
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

Hi,

Try that and let me know if I didn't understand someting.

```
var nb=numberOfFields;
var theSum=0;
var noBlank=0;
for (var i=1; i<=nb; i++) {
theSum+=Number(this.getField("FINALscoreS"+i).value);
if (this.getField("FINALscoreS"+i).valueAsString!="") noBlank++;
}
event.value=theSum*100/(13*noBlank);
```

@+

Community guidelines

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

soulglowdeej
AUTHOR

Contributor
,

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12807313#M88861
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

Hi Bebarth,

Thanks so much for answering.

Unfortunately I'm only getting a result of 0, no matter what value is in the 'FINALscoreS#' fields.

Reading the code (from my limited understanding) it looks like you've understood what I'm after, it's just not working as it should...Thanks again for trying to help, it's hugely appreciated 🙂

P.S. The fields are on separate pages...that didn't used to make any difference as far as a I remember, but thought I'd mention it just in case.

Community guidelines

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

soulglowdeej
AUTHOR

Contributor
,

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12807318#M88862
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

ooooh...the "FINALscoreS" fields are calculated fields. They work fine as it's simple x+x...would that matter?

Thanks again

Community guidelines

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12807442#M88863
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

Community guidelines

soulglowdeej
AUTHOR

Contributor
,

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12807470#M88864
Mar 11, 2022
Mar 11, 2022

Copy link to clipboard

Copied

aaah!!! FANTASTIC! I understand now, I needed to add the variable number. My mistake, i didn't get that.

This is perfect!! Thanks so much for your help. You have no idea how much I appreciate it 🙂

Thanks so again! 🙂 🙂 🙂 🙂 🙂 🙂 🙂

Community guidelines

/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12980025#M89384
Jun 01, 2022
Jun 01, 2022

Copy link to clipboard

Copied

Community guidelines

Community Expert
,

LATEST
/t5/acrobat-sdk-discussions/javascript-maths-calculation-sum-countif/m-p/12980232#M89386
Jun 02, 2022
Jun 02, 2022

Copy link to clipboard

Copied

There is no alternative. If JS is disabled calculations will not work.

Community guidelines

Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português
- 한국어

Copyright © 2022 Adobe. All rights reserved.