PDF Editing Issues

How to Create an Acrobat Calculation Script for Conditional Totals

Jason MillerJason Miller Nov 10, 2026 869 views

Question details

The user needs a method to replicate Excel's SUMIFS logic inside an Adobe Acrobat PDF form to sum values into distinct totals based on specific text conditions.

How to Create an Acrobat Calculation Script for Conditional Totals
Product
Adobe Acrobat / PDF Form
Device & OS
not provided
Scenario
Setting up advanced PDF form calculations where numeric inputs must be routed to different subtotal fields depending on an adjacent categorical text field.
Observed behavior
The user wants 'PW' field values to be added to either a 'B' total or an 'S' total depending on whether the corresponding 'PT' field contains a 'B' or 'S'.
Before you start

Verify that your PDF form fields follow a consistent and sequential naming convention (e.g., PT1, PT2, PW1, PW2) so that a loop script can process them correctly.

Solution 1Recommended

Use a JavaScript Loop to Calculate Conditional Totals

Apply a custom JavaScript calculation script in your PDF form to loop through all input fields and conditionally sum the values based on specific text parameters.

Since PDF forms do not natively support Excel's SUMIFS formula, you must use JavaScript. By iterating through the sequential field names, the script checks the condition of the type field and adds the corresponding amount to the correct total variable.

1
Access Field Properties

Open your PDF form in edit mode. Right-click on the target field where you want the total to appear (for example, 'BTOTAL') and select 'Properties' from the context menu.

2
Set Calculation Option

Navigate to the 'Calculate' tab in the Properties window. Select the 'Custom calculation script' option, and then click the 'Edit' button to open the JavaScript editor.

3
Input the JavaScript Loop

Enter the following loop script into the editor: `var Btotal=0, Stotal=0; for(var i=1;i<=38;i++){var type=this.getField("PT"+i).valueAsString; var amount=Number(this.getField("PW"+i).value); if(type==="B") Btotal+=amount; else if(type==="S") Stotal+=amount;} this.getField("BTOTAL").value=Btotal; this.getField("STOTAL").value=Stotal;`

4
Save and Test the Form

Click 'OK' to save the script and close the Properties window. Switch to preview or fill mode to test the logic by entering 'B' or 'S' in your text fields and numerical values in the corresponding amount fields.

Use a JavaScript Loop to Calculate Conditional Totals
Adjusting Script Parameters: Ensure you adjust the loop limit (e.g., changing '38' to the actual number of rows in your form) and match the exact field names (PT, PW, BTOTAL, STOTAL) used in your document to avoid script errors.
Advanced PDF Form Management

Edit and Manage PDF Forms Seamlessly with WPS Office

WPS Office offers a comprehensive PDF editor that allows you to easily view, manage, and fill interactive PDF forms, making it an excellent all-in-one productivity suite for your daily document workflows.

  1. 1. Download WPS Office: Visit the official WPS website to download and install WPS Office for free.
  2. 2. Open Your PDF Form: Launch WPS PDF and open your interactive PDF document containing form fields.
  3. 3. Fill and Edit: Use the integrated PDF tools to navigate form fields, input data smoothly, and add electronic signatures if required.
  4. 4. Save or Export: Save your completed document locally or export it to share with others seamlessly.
Smoothly fill out, edit, and sign interactive PDF forms.Fully compatible with standard Adobe PDF document formats.Lightweight application that integrates Word, Excel, PowerPoint, and PDF editing seamlessly.
QA img-9

Frequently Asked Questions

Can I use Excel's SUMIFS function directly in a PDF form?

No, PDF forms do not support native Excel functions like SUMIFS. To achieve conditional calculations, you must use Adobe Acrobat's custom JavaScript calculation scripts.

Why isn't my Acrobat calculation script updating automatically?

This usually happens due to the calculation order. Ensure that your total fields are calculated after all the referenced input fields. You can adjust the calculation order in the form editing menu.

What happens if a field is left blank while running the script?

If an amount field is blank, the Number() function in JavaScript will typically treat it as zero. However, it's best practice to ensure input fields are validated to avoid returning 'NaN' (Not a Number) errors in your totals.