logo
search
Others

How to Subtract Array Values by Index in Power Automate for Desktop

Algirdas JasaitisAlgirdas Jasaitis Oct 1, 2026 869 views

Question details

The user needs to calculate the difference between matching values stored in two separate arrays by using a variable index.

How to Subtract Array Values by Index in Power Automate for Desktop
Product
Power Automate for Desktop
Device & OS
not provided
Scenario
Extracting text from a PDF, storing the numerical positions of specific phrases into arrays, and subtracting one array's values from another.
Observed behavior
The user is looking for the correct syntax and logic to access array elements via an index variable and perform the subtraction.
Before you start

Ensure you have successfully extracted the PDF text and that both arrays are populated with numerical position values before setting up the subtraction logic.

Solution 1Recommended

Use a Loop Counter for Array Subtraction

Utilize a loop counter variable to iterate through the arrays, retrieve corresponding elements by their index, and calculate their difference.

To subtract values stored in two different arrays, you must use a shared index. Since Power Automate for Desktop processes lists sequentially, a standard loop configuration allows you to reference the exact position in both arrays simultaneously.

1
Initialize a Loop

Add a 'Loop' action to your flow. Set the 'Start from' value to 0, and the 'End to' value to `%Array1.Count - 1%`. Name the loop variable `%LoopIndex%`.

2
Retrieve Array Values

Inside the loop, use the syntax `%Array1[LoopIndex]%` and `%Array2[LoopIndex]%` to access the specific positional values you extracted from the PDF.

3
Perform Subtraction

Add a 'Set variable' action inside the loop. In the value field, enter the expression `%Array2[LoopIndex] - Array1[LoopIndex]%` to calculate the difference and store it in a new variable.

Use a Loop Counter for Array Subtraction
Syntax Validation: If you receive a syntax error, ensure that your array values are stored as numbers rather than text strings. You may need to use the 'Convert text to number' action first.
Free Microsoft Office alternative

Need an Easier Way to Process PDFs? Try WPS Office

While Power Automate is powerful for creating automated text extraction scripts, WPS Office provides built-in, user-friendly tools for editing, converting, and managing PDF text directly without complex programming. It serves as a lightweight, highly compatible alternative to Microsoft Office.

  1. 1. Download and Install: Get WPS Office from the official website and follow the installation prompts.
  2. 2. Open Your Document: Launch WPS Office and open your target PDF, Word, or Excel document.
  3. 3. Use Built-in PDF Tools: Navigate to the PDF tab to extract text, convert files, or edit content without needing automated scripts.
Seamlessly compatible with Microsoft Word, Excel, PowerPoint, and PDF document formats.Built-in PDF editor allows you to extract and modify text directly without building automation flows.Lightweight application with a familiar tabbed interface for easy document management.Completely free to use for everyday office tasks and basic PDF processing.
microsoft office alternative - wps office

Frequently Asked Questions

Why am I getting an out-of-bounds error when accessing the array?

This error occurs if your loop counter exceeds the number of items stored in the array. Ensure your loop condition ends at `%Array.Count - 1%` since Power Automate arrays are zero-indexed.

Can I subtract array values directly without a loop in Power Automate?

No, Power Automate for Desktop does not support direct matrix or array-level arithmetic natively. You must iterate through the arrays using a loop or run a custom script (like VBScript or Python) to process the elements.

How do I ensure my array values are treated as numbers instead of text?

When extracting text from a PDF, the values are often stored as string data types. Use the 'Convert text to number' action in your flow on each array element before attempting to perform mathematical subtraction.