How to Exclude Empty Fields from an Acrobat PDF Calculation
Question details
The user wants to calculate the average of multiple fields in a PDF form without the calculation treating empty fields as zeros.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form that requires an accurate average calculation based only on user-filled fields.
- Observed behavior
- By default, Acrobat counts empty fields as zero values, which incorrectly lowers the resulting average. The goal is to ignore the empty fields entirely during the calculation.
Ensure you have access to the form editing tools in your PDF application. It is recommended to save a backup copy of your PDF form before applying custom scripts.
Use a Custom JavaScript Calculation
Implement a custom JavaScript script in your PDF form to check for values, sum only populated fields, and divide the total by the exact count of those filled fields.
Acrobat's built-in average function includes all specified fields, treating blanks as zeros. To bypass this, you must use a custom calculation script (commonly referred to as the 'calcAverage' script pattern).
Open your PDF document in Adobe Acrobat and select the 'Prepare Form' tool from the tools menu.
Right-click on the destination text field where you want the calculated average to appear, and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab within the Properties window. Choose the 'Custom calculation script' radio button.
Click the 'Edit' button and enter a JavaScript code loop. The script should verify if each field contains a value, add only the populated fields to a running total, and divide by the number of completed fields.
Click 'OK' to apply the script, close the Properties window, and enter test values into your form fields to confirm that empty fields are successfully ignored.

Simplify Calculations with WPS Office
Writing custom JavaScript for PDF forms can be complex. With WPS Office, you can quickly convert your PDF forms into Excel spreadsheets to handle complex averages and calculations natively, without any programming.
- 1. Open Your PDF in WPS: Launch WPS Office and open your PDF form using the WPS PDF viewer.
- 2. Convert to Spreadsheet: Navigate to the 'Tools' tab and click on 'PDF to Excel' to extract your form fields into a structured spreadsheet.
- 3. Apply an Average Formula: In the converted spreadsheet, simply use the standard =AVERAGE() formula, which automatically ignores empty cells, completely bypassing the need for JavaScript.
- 4. Export Back to PDF: Once your data is calculated, you can save the spreadsheet or export it back to PDF format by selecting 'Export to PDF'.

Frequently Asked Questions
Why does my PDF form treat empty fields as zeros?
By default, the standard built-in calculation functions in Acrobat read empty numerical fields as zero values. A custom script is required to explicitly instruct the software to skip empty fields during the calculation.
Can I calculate an average ignoring blanks without using JavaScript?
No, Acrobat's default 'Value is the average of the following fields' setting does not have an option to ignore blanks. A custom JavaScript calculation is the only native way to achieve this in a PDF form.
What is the 'calcAverage' script?
'calcAverage' is a widely recognized JavaScript pattern used by PDF developers. It iterates through an array of specified form fields, counts only those that contain data, sums their values, and divides by the precise count of filled fields.




