Use Excel Power Query to Convert Alternating Invoice Rows into Columns
Question details
Convert alternating rows of PDF invoice data into separate item and value columns using a repeatable Power Query workflow.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- Invoice data has been loaded from a PDF into one Excel query column, and monthly invoices may contain different numbers of rows.
- Observed behavior
- The desired result is one row per item and value pair, with the query able to handle varying invoice lengths when refreshed.
Open the invoice query in Power Query Editor and check that the data column contains consistent item-then-value pairs. Remove headers or extra rows before adding an index, because they can shift the pairing.
Pivot alternating rows using a pair number and row type
Use an index to identify each pair and pivot its two rows into separate columns, regardless of the number of invoice rows.
In Excel, select Data > Queries & Connections, then open the query containing the imported invoice column in Power Query Editor.
Select Add Column > Index Column > From 0. Confirm that the first item has index 0 and its value has index 1.
Select Add Column > Custom Column, name it Pair, and enter Number.IntegerDivide([Index], 2). This assigns the same pair number to each item and its following value.
Select Add Column > Custom Column, name it RowType, and enter Text.From(Number.Mod([Index], 2)). The resulting 0 identifies an item row and 1 identifies a value row.
Remove the Index column and any other columns that distinguish rows within a pair. Select RowType, choose Transform > Pivot Column, select the original invoice data column as Values Column, and choose Don't Aggregate under Advanced options.
Rename the pivoted 0 and 1 columns to Item and Value. Remove Pair if it is no longer needed, then select Home > Close & Load.
When the monthly source changes, update the PDF source in the query if necessary, then select Data > Refresh All. Check that the new invoice follows the same alternating row pattern.

Review Converted Invoice Tables in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar interface. Open compatible Excel workbooks to review and edit converted invoice tables; the Excel Power Query transformation itself must be run in Excel.

Frequently Asked Questions
Why do I need a Pair column before pivoting?
The Pair column gives each item and its following value a shared identifier. Without it, multiple rows would have the same RowType, so Power Query could not reliably place each value beside its item without aggregation.
What if my invoice lists the value before the item?
The pivot still works, but the meanings are reversed: rename column 0 to Value and column 1 to Item. Check the order in the source query before adding the index.
Will the query work when an invoice has more or fewer rows?
Yes, if the new data follows the same alternating pattern. Update the source if needed and select Data > Refresh All; the index and pair numbers are recalculated.
Why are items paired with the wrong values?
An extra header, blank row, or missing value can shift the alternating pattern. In Power Query Editor, filter or remove unwanted rows before the Index step, and check for missing entries in the source.
Can WPS Office run this Excel Power Query transformation?
This workflow uses Excel Power Query, so run and refresh it in Excel. WPS Spreadsheet can open compatible Excel workbooks to review or edit the resulting table.




