Skip to main content
New Participant
June 26, 2018
Question

how to add multiple fields and then divide

  • June 26, 2018
  • 5 replies
  • 1396 views

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.

This topic has been closed for replies.

5 replies

New Participant
June 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?

try67
Community Expert
June 26, 2018

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.

New Participant
June 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.

try67
Community Expert
June 26, 2018

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

New Participant
June 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 : "";

try67
Community Expert
June 26, 2018

What happens when the fields are empty?

try67
Community Expert
June 26, 2018
Bernd Alheit
Community Expert
June 26, 2018

You can use JavaScript for this.