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

how to add multiple fields and then divide

New Here ,
Jun 25, 2018 Jun 25, 2018

I need to add together two columns "Actual Hours" and "Actual Pets", then divide to get "Hours/Pet". I then need a running total for each day of the week that provides the week to date and the month to date.

My goal is this: (AHMonday + AHTuesday + AHWednesday + AHThursday + AHFriday) / (APMonday + APTuesday + APWednesday + APThursday + APFriday)

The average is not the same as week to date (off slightly, but very important this be accurate) and I need to account for fields being empty without sending errors for not completing the calculations. I am using adobe acrobat pro.

TOPICS
Acrobat SDK and JavaScript , Windows
1.2K
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 26, 2018 Jun 26, 2018

You can use JavaScript for this.

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 26, 2018 Jun 26, 2018
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
New Here ,
Jun 26, 2018 Jun 26, 2018

Sorry, I intend to use javascript and have looked over that link but I am still not able to write the javascript I need. Its the week to date and month to date I am struggling with. The simple calculation worked great until I ran into the errors for having the document not filled in yet. This is what I have for "Para/Pet" for Monday:

var numerator = +getField("AHMonday").value;

var denominator = +getField("APMonday").value;

event.value = denominator !== 0 ? numerator / denominator : "";

Screenshot (13).png

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 26, 2018 Jun 26, 2018

What happens when the fields are empty?

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
New Here ,
Jun 26, 2018 Jun 26, 2018

"The value entered does not match the format of the field". This happens when there is a field blank. The form would be filled out during the month and build up so keeping blank fields out of the calculations is pretty important.

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 26, 2018 Jun 26, 2018

The code you posted above should prevent that from happening. I tested it and it works fine for me...

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
New Here ,
Jun 26, 2018 Jun 26, 2018

The code I posted works perfectly to calculate "Para/Pet" but how do I enter the week to date and month to date?

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 26, 2018 Jun 26, 2018
LATEST

You mean the formula in your original post? You need to use the same logic.

Create a variable that holds the numerator value and one that holds the denominator, and only apply the calculation if the latter is not zero.

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