Forum Discussion
Patrick2788
Dec 15, 2023Silver Contributor
Solving 'The Assignment Problem' with Lambda
The Setup The problem is simple. Given a 'cost matrix', assign tasks to workers to minimize total cost needed to complete the tasks. Workers may not perform more than 1 task. Assignment p...
- Dec 19, 2023
In attached file PQ Assignment2 generates the required rows only
Though, it's slower than djclements initial approach (PQ Assignment1)
Lorenzo
Dec 19, 2023Silver Contributor
In attached file PQ Assignment2 generates the required rows only
Though, it's slower than djclements initial approach (PQ Assignment1)
SergeiBaklan
Dec 19, 2023Diamond Contributor
DAX is not the tool for such tasks, however tried to repeat with it
DEFINE
VAR WorkerA =
SELECTCOLUMNS ( 'Table', "Worker A", 'Table'[Worker], "Cost A", 'Table'[A] )
VAR WorkerB =
SELECTCOLUMNS ( 'Table', "Worker B", 'Table'[Worker], "Cost B", 'Table'[B] )
VAR WorkerC =
SELECTCOLUMNS ( 'Table', "Worker C", 'Table'[Worker], "Cost C", 'Table'[C] )
VAR Combinations =
CROSSJOIN ( WorkerA, WorkerB, WorkerC )
VAR minCost =
MINX ( Combinations, [Cost A] + [Cost B] + [Cost C] )
VAR Assignment =
FILTER (
Combinations,
[Worker A] <> [Worker B]
&& [Worker A] <> [Worker C]
&& [Worker B] <> [Worker C]
&& [Cost A] + [Cost B] + [Cost C] = minCost
)
EVALUATE
Assignment- LorenzoDec 19, 2023Silver Contributor
I'm not good at DAX but see exactly what you query does. Well done!