Power Query Problems

Solve the Assignment Problem in Excel with LAMBDA or Power Query

Aamir Naveed AkramAamir Naveed Akram Nov 12, 2026 872 views

Question details

The user needs to match workers to tasks exactly once while minimizing the total assignment cost.

Solve the Assignment Problem in Excel with LAMBDA or Power Query
Product
Microsoft Excel LAMBDA and Power Query
Device & OS
not provided
Scenario
A cost table contains possible worker-task combinations, and the user wants to generate valid assignments, compare their total costs, and identify all minimum-cost results.
Observed behavior
Generating permutations can create thousands of unnecessary rows, especially as the input table grows, and duplicate workers must be filtered before comparing costs.
Before you start

Prepare a source table with one row per worker-task option and columns such as Worker, Task, and Cost. Confirm that task names and worker identifiers are consistent, and decide whether tied minimum-cost assignments should all be returned.

Solution 1Recommended

Use Power Query to generate and filter valid assignments

Use this approach when the source data is a table of worker-task-cost combinations and you need a repeatable query that returns every tied minimum-cost assignment.

Power Query can create candidate combinations through many-to-many joins, calculate each assignment's total cost, and reject combinations that reuse a worker. This method is transparent and refreshable, but a full permutation can become expensive for larger matrices.

1
Load the cost table

Select any cell in the Worker, Task, and Cost table, open the Data tab, choose From Table/Range, and confirm that the table has headers in Power Query Editor.

2
Create task-position copies

In Power Query Editor, duplicate the task list or create one query for each required task position. Use Home > Merge Queries and select the worker-task source as the second table; configure the merge as a many-to-many match using the task or assignment key.

3
Expand candidate workers and costs

Select the expand button on the merged column and include Worker and Cost. Repeat the merge and expansion for each task position so every candidate row contains one worker and cost for every task.

4
Remove assignments that reuse a worker

Choose Add Column > Custom Column and compare the worker columns. Keep only rows where every worker value is different, then use Home > Remove Rows > Remove Duplicates if identical assignment rows remain.

5
Calculate and filter the minimum cost

Choose Add Column > Custom Column, add the cost columns together, and name the result Total Cost. Use Transform > Statistics > Minimum or a grouped summary to find the lowest Total Cost, then filter the assignment table to that minimum and select Home > Close & Load.

Control permutation growth: For larger matrices, generating every permutation can produce thousands of unnecessary rows. Use Solver or a dedicated assignment algorithm when the query becomes slow or exceeds practical row limits.
Free Microsoft Office alternative

Build clear spreadsheet models with WPS Office

WPS Office is a free, lightweight Microsoft Office alternative for organizing worker-task cost tables, writing compatible spreadsheet formulas, and reviewing assignment results in a familiar interface. It supports seamless migration through common Microsoft Excel formats, although Microsoft-specific Power Query and LAMBDA behavior may require Excel for full execution.

Create and analyze worker-task cost tables in a clean, familiar spreadsheet interface.Open, edit, and save Microsoft Excel XLSX files for easier migration and collaboration.Use a lightweight free office suite when you need to review assignment calculations without installing a full Microsoft Office package.Keep source data, candidate assignments, and minimum-cost results organized in one workbook.
QA img-9

Frequently Asked Questions

How does Power Query find the lowest-cost assignment?

After generating valid combinations, add a Total Cost custom column by summing the cost fields. Find the minimum value with a grouped summary or a minimum statistic, then filter the assignment query to that value.

How can I prevent the same worker from being assigned twice?

After expanding the merged worker columns, add a custom column that checks whether each worker column is different from the others. Filter the result to TRUE before calculating or comparing total costs.

Will Power Query return all tied optimal assignments?

Yes. Calculate the minimum Total Cost, then filter the complete assignment table with Total Cost equal to that minimum. Every valid row with the same lowest cost remains in the output.

Why does the Power Query solution become slow with more workers and tasks?

A permutation approach grows rapidly because it creates many candidate rows before filtering invalid assignments. For larger matrices, use Excel Solver, an assignment algorithm, or early filtering to reduce the candidate set.

Can WPS Office run Microsoft Excel Power Query or LAMBDA formulas exactly?

WPS Office can open and edit compatible XLSX workbooks, but Microsoft-specific Power Query and newer LAMBDA behavior may not run identically. Use WPS for spreadsheet preparation and review, and use supported Excel for full Power Query execution.