Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEALast week's challenge can be found HERE!
You have been given some order information that contains a list of orders with SKUs and related quantities. Additionally, you have a data set with the total inventory for each SKU.
You have been tasked with figuring out how to consume all of the inventory with the least amount of orders. In other words, you have been asked to fill the largest orders for each SKU in descending order.
Additionally, only complete orders may be fulfilled. For example, if an order calls for 4 units of a SKU, and only 3 are left in inventory, you can't fulfill the order.
nice one!
this solution uses a basic "Fill in reverse size order" principle - but this doesn't guarantee maximum packing - with different order data, we may need to add an iterative macro or some other Knapsack process to maximize fill.
But for this input data, it matches the provided output.
Here's my solution :)
Loved that you made it sound so easy before the complete orders only caveat ;)
My solution.
@BenMoss, I have to do at least one caveat. ;)
Had to do this one twice. The first time through I had way too many tools, so tried it again with fewer. :-)
I saw that many people have already provided similar looking solutions, so I decided to go down the iterative macro route that @SeanAdams mentioned. While I've created a macro that gets the correct answer and will allow for some more flexibility, it still has some major gaps. The iterative macro can be tweaked to find all combinations by unchecking the box (and then you could figure out the smallest set for sure), but it quickly blows up the processing because I haven't optimized it yet. It's not very well laid out, but here is my basic logic:
My multirow is a bit crazy, I think it will be interesting to see what other people did. This was definitely a fun one! I never usually get to use multirow in such a way. Thanks Joe :)
It was a good exercise, these challenges are so neat and definitely I learnt a new technique once again! :)
Mina, I just downloaded your workflow and looked at your multirow formula. I did kind of similar thing but I used first a multirow to compute the cumulative/ running total, then a formula to calculate the difference. I like that you did the same just using the multirow formula!
Actually, you could also simplify a little bit your Multirow, as the last IF statement is not needed and you could substitute it with [Row-1:Remaining], so your calc would look like:
IF
(IF [Row-1:Order SKU]=[Order SKU] THEN [Row-1:Remaining] ELSE [Supply] ENDIF)-[Demand]>=0
THEN ((IF [Row-1:Order SKU]=[Order SKU] THEN [Row-1:Remaining] ELSE [Supply] ENDIF)-[Demand]) ELSE
[Row-1:Remaining]
ENDIF