Solve the Assignment Problem in Excel with LAMBDA or Power Query
Question details
The user needs to match workers to tasks exactly once while minimizing the total assignment cost.

- 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.
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.
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.
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.
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.
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.
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.
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.
Use an Excel LAMBDA formula to enumerate candidate assignments
Use this option when you have a modern Excel version with LAMBDA, LET, VSTACK, and related dynamic-array functions and want a formula-driven model.
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.

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.




