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.
var numerator = +getField("AHMonday").value;
var denominator = +getField("APMonday").value;
event.value = denominator !== 0 ? numerator / denominator : "";
What happens when the fields are empty?
"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.
The code you posted above should prevent that from happening. I tested it and it works fine for me...
The code I posted works perfectly to calculate "Para/Pet" but how do I enter the week to date and month to date?
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.