PDF Editing Issues

How to Use SUMIF and COUNTIF Logic in Acrobat PDF Forms

Adam DavisAdam Davis Nov 10, 2026 869 views

Question details

The user needs to apply conditional logic similar to SUMIF and COUNTIF within a fillable PDF form to calculate total hours for specific activity codes without double-counting duplicate rows.

How to Use SUMIF and COUNTIF Logic in Acrobat PDF Forms
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an advanced interactive PDF form that requires conditional mathematics to sum values and count activities based on specific criteria while ignoring duplicate indicators.
Observed behavior
Native PDF forms do not support Excel-style formulas directly, so custom JavaScript must be written to loop through fields, validate conditions, and output the correct sum.
Before you start

Before writing your script, map out all exact field names in your form (e.g., activity codes, hours, repeat checkboxes) and determine the maximum number of rows your loop will need to process.

Solution 1Recommended

Implement Custom JavaScript for Conditional PDF Calculations

Use Adobe Acrobat's custom calculation script feature to loop through form fields, track duplicates, and replicate conditional summing.

Since PDFs do not use standard spreadsheet formulas, you must use JavaScript to evaluate the form data. The script will need to iterate through each row, check the activity code, verify if the row has already been counted, and then add the hours to a running total.

1
Standardize your form field names

Ensure your fields follow a sequential naming convention, such as 'ActivityCode.0', 'ActivityCode.1', and 'Hours.0', 'Hours.1'. This makes it easier to write a looping script.

2
Access field properties

Right-click the text field where you want the final sum to appear and select 'Properties' from the context menu.

3
Enable custom calculations

Navigate to the 'Calculate' tab in the Properties window, select the 'Custom calculation script' radio button, and click the 'Edit' button.

4
Write the loop and condition logic

Enter JavaScript that loops from 0 to your maximum row count. Use an array to store activity codes that have already been evaluated so that duplicate rows are skipped, and add the corresponding 'Hours' field value to your total variable if the condition is met.

Implement Custom JavaScript for Conditional PDF Calculations
JavaScript Knowledge Required: Writing custom calculations requires a basic understanding of Acrobat JavaScript APIs. If the number of rows or field names changes later, you will need to update the script accordingly.

Manage and Fill Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive and user-friendly PDF editor that allows you to easily view, fill, and manage interactive PDF forms without complex setups.

  1. 1. Open your PDF: Launch WPS Office and open your fillable PDF document.
  2. 2. Access form features: Navigate to the 'Form' tab on the top ribbon to interact with or highlight fillable fields.
  3. 3. Fill and evaluate: Enter your data into the fields. Forms with pre-configured calculation scripts will automatically update totals as you type.
  4. 4. Save and share: Click 'Save' or export the filled document to your device while retaining all form data and formatting.
Seamlessly view and fill interactive PDF forms with high compatibilityFully compatible with Adobe Acrobat PDF formats and form fieldsLightweight alternative with built-in tools for editing text and adding signaturesCross-platform support for Windows, Mac, and mobile devices
microsoft office alternative - wps office

Frequently Asked Questions

Can I use standard Excel formulas like SUMIF directly in a PDF?

No, PDF forms do not support native spreadsheet formulas like SUMIF or COUNTIF. You must use custom JavaScript to replicate this conditional behavior.

How do I prevent my PDF calculation from counting duplicate rows?

Within your custom calculation script, you need to create an array or object to track which activity codes or repeat indicators have already been counted. As the loop processes each row, it should check this tracking array and skip the row if a match is found.

Where do I input the calculation script in an Acrobat PDF form?

Right-click the specific output text field (where the total should appear), select Properties, navigate to the Calculate tab, and choose 'Custom calculation script' to enter your JavaScript code.

Why is my PDF form calculation not updating automatically?

This usually happens due to the calculation order or incorrect field names in the script. Ensure your script references the exact field names (case-sensitive) and check your form's calculation order settings if multiple calculated fields depend on each other.