How to Sum PDF Form Fields While Ignoring N/A and Blank Values
Question details
The user needs to create an Acrobat or PDF form calculation that adds up numeric ratings to find a total sum, specifically ensuring that N/A, blank spaces, and other non-numeric entries are excluded from the operation.

- Product
- Device & OS
- not provided
- Scenario
- Setting up a PDF form field to calculate the sum of multiple user inputs to later determine a percentage, where respondents might input text like "N/A" or leave fields blank.
- Observed behavior
- Standard built-in sum calculations may fail or process incorrectly when encountering non-numeric text strings like "N/A", requiring a custom JavaScript solution to filter out invalid data.
Before adding your calculation script, ensure all target form fields have distinct, recognizable names. Decide logically whether a blank field should be treated mathematically as a zero or completely ignored in your specific rating scale.
Use Custom JavaScript to Filter and Sum Values
Apply a custom calculation script in the PDF form field properties to convert inputs to numbers and skip any non-numeric strings.
To reliably filter out non-numeric values like "N/A" or blanks, you need to use a custom JavaScript rather than the default sum function. The script will retrieve each field's value as a string, check if it is a valid number using the `isNaN()` function, and only add it to the total sum if it passes the check.
Open your PDF document in your PDF editor, navigate to the Form tools, and enter the form editing mode.
Right-click the destination text field where you want the final sum to appear and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab at the top of the Properties dialog box. Select the 'Custom calculation script' option and click the 'Edit' button.
Enter a script that loops through your field names. Read the value using `var v = this.getField(aFieldNames).valueAsString;`. Then, add the condition `if (!isNaN(Number(v))) nSum += Number(v);` to safely sum the values. Finally, output the result using `event.value = nSum;`.
Click 'OK' to save the script, close the Properties dialog, and exit form editing mode. Test the form by entering numbers, "N/A", and leaving some fields blank to ensure the total updates correctly.

Create and Calculate PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, allowing you to seamlessly insert interactive form fields, configure advanced custom JavaScript calculations, and manage your documents professionally.
- 1. Open your PDF: Launch WPS Office and open the PDF form you need to edit.
- 2. Access Form tools: Navigate to the 'Form' tab on the top ribbon to insert new text fields or interact with existing ones.
- 3. Apply calculations: Double-click a form field to open its properties, switch to the 'Calculate' tab, and easily set up your custom sum or average formulas.

Frequently Asked Questions
Why does my PDF form sum calculation show an error when N/A is entered?
Standard PDF sum functions expect purely numeric inputs. When a text string like "N/A" is entered into a field included in the sum, the calculation fails or returns an error. You must use a custom JavaScript validation to filter out non-numeric strings.
Can I calculate an average instead of a sum while ignoring blank fields?
Yes. In your custom JavaScript, you can maintain a counter variable (e.g., `nCount`). Increment this counter only when the field contains a valid number. At the end of the script, divide your total sum by the counter (`event.value = nSum / nCount;`) to get the true average.
How do I ensure blank fields are not treated as zero in my calculation?
By default, some PDF readers treat empty fields as zero. To avoid this, your custom script should check if the field's `valueAsString` is completely empty (e.g., `v !== ""`) before converting it to a number and adding it to your sum or average counter.




