Calculate a PDF Form Average Excluding Blank and N/A Fields in Adobe Acrobat
Question details
Calculate the average of PDF form ratings without counting blank or N/A fields, and optionally select a radio button based on the rounded result.

- Product
- PDF form editor with JavaScript calculation support
- Device & OS
- not provided
- Scenario
- A PDF form contains rating fields, an average field, and a radio group representing the rounded rating.
- Observed behavior
- The desired average uses only valid numeric ratings, and the corresponding radio option is selected using its export value.
Open the form in a PDF editor that supports custom JavaScript calculations, such as Adobe Acrobat Pro. Note the exact names of the rating fields, average field, and radio group, as well as each radio option’s export value.
Use an Acrobat calculation script to average valid ratings
Use this method to calculate the average automatically and select a radio option based on the rounded result.
The script counts only nonblank values that can be converted to finite numbers. It leaves the average blank when no valid ratings are available.
The radio mapping below is an example. Replace the field names and export values with those in your form; a radio option’s label is not necessarily its export value.
In Adobe Acrobat Pro, open the PDF and choose All tools > Prepare a form. Double-click the field that should display the average, then open its Calculate tab.
Select Custom calculation script, click Edit, and paste the following script. Replace Rating1 through Rating3 and RatingGroup with your actual field names, and replace Choice1 through Choice5 with the radio options’ actual export values. var names = ["Rating1", "Rating2", "Rating3"]; var sum = 0; var count = 0; for (var i = 0; i < names.length; i++) { var field = this.getField(names[i]); if (!field) continue; var text = String(field.valueAsString).replace(/^\s+|\s+$/g, ""); if (text === "") continue; var number = Number(text); if (!isFinite(number)) continue; sum += number; count++; } event.value = count > 0 ? sum / count : ""; var radio = this.getField("RatingGroup"); var options = {"1": "Choice1", "2": "Choice2", "3": "Choice3", "4": "Choice4", "5": "Choice5"}; if (radio) { var rounded = count > 0 ? String(Math.round(sum / count)) : ""; radio.value = options[rounded] || "Off"; }
In Prepare a form, double-click each radio button and check its Options tab. Update the script’s options mapping to match the export values for the corresponding ratings.
Save the PDF and use Preview in Prepare a form to enter ratings, leave fields blank, and enter N/A. Confirm that only numeric ratings affect the average and that the expected radio option is selected.

Calculate the rating average with WPS Spreadsheet
For a manual alternative, copy the PDF ratings into WPS Spreadsheet, calculate the average while ignoring blank cells and text such as N/A, then enter the result and select the matching option in the PDF. This does not add automatic calculations to the PDF form.
- 1. Enter the ratings: Open WPS Spreadsheet, create a workbook, and enter the form ratings in cells A2 through A10. Leave missing ratings blank and enter N/A as text.
- 2. Calculate the average: In another cell, enter =IF(COUNT(A2:A10)=0,"",AVERAGE(A2:A10)) and press Enter. Adjust the range to include all rating cells.
- 3. Round the result: If the average is displayed in B2, enter =IF(B2="","",ROUND(B2,0)) in another cell to identify the matching whole-number rating.
- 4. Update the PDF: Open the PDF in WPS Office, enter the average in the form field, and select the radio option matching the rounded result if the form is fillable.

Frequently Asked Questions
Why is the radio button not selected when the average is 3?
The radio group must be assigned the option’s export value, which may differ from its visible label or field name. In Acrobat’s Prepare a form tool, open the radio button’s Properties > Options and check its export value.
What happens when all rating fields are blank or N/A?
The script sets the average field to an empty value because the valid-number count is zero. It also assigns Off to the radio group.
Does the script exclude zero ratings?
No. Zero is a valid number and is included in both the sum and count. If zero means “not rated” in your form, change the script’s condition to exclude it.
Can I calculate the average in WPS Spreadsheet instead?
Yes. Enter the ratings in cells and use =IF(COUNT(A2:A10)=0,"",AVERAGE(A2:A10)). Blank cells and text such as N/A are ignored, but error values such as #N/A are not; replace those errors before calculating.




