How to Implement Row-by-Row Allocation with List.Generate in Excel Power Query
Question details
The user needs to process generation data one row at a time in Power Query by repeatedly selecting the engine with the highest remaining value, allocating power, removing that engine from the queue, and continuing until demand is met.

- Product
- Power Query in Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user is building a Power Query transformation for generation data with engines E1 through E9 and wants each row to allocate power to engines according to their remaining values until the row demand is satisfied.
- Observed behavior
- The current M code fails or produces incorrect allocation because the engine list is not defined with List.Transform and the transformed table is not referenced consistently.
Confirm that the source table is loaded into Power Query and that the demand column and engine columns E1 through E9 are numeric. In the Advanced Editor, create a transformed table step and an engine list variable before building the List.Generate expression.
Use List.Generate to Allocate Power Row by Row in Power Query
Use this when you need to process each generation row independently, repeatedly choosing the engine with the highest remaining value until demand is met.
Power Query evaluates table transformations in a fixed order. For row-by-row allocation, create a stable transformed table and an engine list such as E1 through E9, then pass that table into List.Generate for each row.
The generator state tracks the remaining value for each engine. It selects the maximum remaining value, allocates the required amount, removes the selected engine, and continues until demand is satisfied.
In the Advanced Editor, define the engine list as: EngineList = List.Transform({1..9}, each "E" & Text.From(_)). This creates E1, E2, ... E9 and avoids hard-coded or missing engine names.
Create a transformed table variable, for example TransformedTable = YourPreviousStep, and use TransformedTable throughout the List.Generate expression instead of mixing source and transformed references.
Add a custom column that calls List.Generate for each row. Use the row's Demand value as the loop condition and pass the row record or engine values as the initial generator state.
Inside the generator, find the engine with the maximum remaining value, allocate the required amount up to that engine's remaining value, then remove that engine from the engine list so the next iteration picks the next highest engine.
Have the final generator element return the allocation record or list. Close the custom column and expand the result fields so each row shows the allocated amounts and selected engines.

Validate the Allocation Logic Against Business Rules
Use this after implementing List.Generate to confirm that the selected engine order and allocated amounts match the required allocation rules.
Work with Excel Files and Data Allocation in a Free, Lightweight Office Suite
This Power Query List.Generate allocation task belongs to Microsoft Excel Power Query and is not fully replaced by WPS Office. For everyday spreadsheet work, WPS Office is a free, lightweight Office alternative that opens and saves .xlsx files, keeps a familiar interface, and lets you migrate from Excel without reformatting your data.
- 1. Download WPS Office: Visit the official WPS site and download WPS Office for Windows, macOS, Android, or iOS, then complete the free installation.
- 2. Open your Excel workbook: Launch WPS Spreadsheets and open the .xlsx file that contains your generation data. WPS Office preserves the workbook structure, formulas, and sheets.
- 3. Continue everyday editing: Use the familiar spreadsheet tools and formatting options in WPS Office for regular data work. For advanced Power Query/M code, keep the original Excel Power Query environment.

Frequently Asked Questions
Why does my Power Query code say the engine list is not defined?
The engine list must be created explicitly before List.Generate uses it. Define it with List.Transform({1..9}, each "E" & Text.From(_)) so Power Query can find E1 through E9. If you reference a column that does not exist or mix the source and transformed tables, the engine list will be missing and the step will fail.
How do I make List.Generate process one row at a time?
Use List.Generate inside a custom column, not as a single top-level loop. Each row then supplies its own demand and engine values. In the initial state, use the current row record or its engine columns, and update the state in each iteration with the remaining engine values and the remaining engine list.
How do I remove an engine after it receives an allocation?
In the next List.Generate state, remove the selected engine from the engine list using List.RemoveItems or List.RemoveMatchingItems. Also remove or zero its remaining value so that the next iteration selects the next eligible engine instead of reusing the same one.
Why does the allocation not match my business rules?
Check three things: always select the maximum remaining engine value, allocate only the required amount up to that engine's remaining value, and stop only when the row demand is met. Also make sure the transformed table passed into List.Generate is the same table used to build the engine list.
Can I run this Power Query List.Generate solution in WPS Office?
This List.Generate allocation method is designed for Microsoft Excel Power Query. WPS Office is a free, lightweight Office alternative that can open and edit Excel workbooks, but advanced Power Query/M code is not fully replaced by WPS Spreadsheets.




