How to Subtract Array Values by Index in Power Automate for Desktop
Question details
The user needs to calculate the difference between matching values stored in two separate arrays by using a variable index.

- 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.
Ensure you have successfully extracted the PDF text and that both arrays are populated with numerical position values before setting up the subtraction logic.
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.
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%`.
Inside the loop, use the syntax `%Array1[LoopIndex]%` and `%Array2[LoopIndex]%` to access the specific positional values you extracted from the PDF.
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.

Consult the Power Automate Community for Advanced Syntax
If you encounter complex variable type errors during flow execution, consult flow specialists on the official Microsoft forums.
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. Download and Install: Get WPS Office from the official website and follow the installation prompts.
- 2. Open Your Document: Launch WPS Office and open your target PDF, Word, or Excel document.
- 3. Use Built-in PDF Tools: Navigate to the PDF tab to extract text, convert files, or edit content without needing automated scripts.

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.




