Power Query Problems

Use Excel Power Query to Convert Alternating Invoice Rows into Columns

Camila MilosovichCamila Milosovich Dec 2, 2026 869 views

Question details

Convert alternating rows of PDF invoice data into separate item and value columns using a repeatable Power Query workflow.

Convert Alternating Invoice Rows into Columns with Excel Power Query
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the invoice query

In Excel, select Data > Queries & Connections, then open the query containing the imported invoice column in Power Query Editor.

2
Add a zero-based index

Select Add Column > Index Column > From 0. Confirm that the first item has index 0 and its value has index 1.

3
Identify each pair

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.

4
Identify the row type

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.

5
Pivot the row type

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.

6
Rename and load the columns

Rename the pivoted 0 and 1 columns to Item and Value. Remove Pair if it is no longer needed, then select Home > Close & Load.

7
Refresh for the next invoice

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.

Pivot alternating rows using a pair number and row type
Check incomplete pairs: If the last item has no matching value, its Value cell will be null. Check the source invoice before using the result.
Free Microsoft Office alternative

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.

Review and edit item and value columns in WPS SpreadsheetCompatible with Microsoft Excel XLSX and XLS formatsFamiliar spreadsheet interface makes migration easierFree, lightweight office suite
microsoft office alternative - wps office

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.