Forum Discussion
Containerization of Orders Function
- 6 years ago
Hi Anonymous ,
if my understanding is correct, you can use this function on the order-level:
// fnContainers (Source, MaxBinQtyColName as text, SKUQtyColName as text ) => let //Source = #"myTable (2)"{1}[Partition], //MaxBinQtyColName = "Max Bin Qty (Function Input)", //SKUQtyColName = "SKU Qty (Function Input)", MaxBinQty = List.First(Table.Column(Source, MaxBinQtyColName)), BufferedList = List.Buffer(Table.Column(Source, SKUQtyColName)), Output = List.Skip(List.Generate( () => [RT = 0, Bin = 0, Counter = 0], each [Counter] <= List.Count(BufferedList), each [ RT = if ( [RT] + BufferedList{[Counter]} ) > MaxBinQty then BufferedList{[Counter]} else [RT] + BufferedList{[Counter]} , Bin = if ( [RT] + BufferedList{[Counter]} ) > MaxBinQty then [Bin] + 1 else [Bin], Counter = [Counter] + 1 ], each [Bin] + 1 )) in OutputTo apply it, your code would look like so (also, see the attached file):
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSAVFgEkgYg1lKsTpwSSMoiVXSGKLTFCZphCxpApE0h0kagyWNkO00hdlriCwHsdIEq5w5hITJGSHLWUDchCQXCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Order (Function Input)" = _t, #"SKU ID (Function Input)" = _t, #"SKU Qty (Function Input)" = _t, #"Max Bin Qty (Function Input)" = _t, #"Container # (Function Output)" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order (Function Input)", Int64.Type}, {"SKU ID (Function Input)", Int64.Type}, {"SKU Qty (Function Input)", Int64.Type}, {"Max Bin Qty (Function Input)", Int64.Type}, {"Container # (Function Output)", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Order (Function Input)"}, {{"Partition", each _}}), #"Invoked Custom Function" = Table.AddColumn(#"Grouped Rows", "Container", each fnContainers([Partition], "Max Bin Qty (Function Input)", "SKU Qty (Function Input)")), #"Added Custom" = Table.AddColumn( #"Invoked Custom Function", "Result", each Table.FromColumns(Table.ToColumns([Partition]) & {[Container]}, Table.ColumnNames([Partition]) & {"Container"})), Custom1 = Table.Combine(#"Added Custom"[Result]) in Custom1This technique should also work fairly fast on large tables.
Hi Anonymous ,
You are welcome!
Item #3, if you look at my previous picture, it does restart for each order due to the ALLEXCEPT().
Item #2 internally for each order per your example, this will work because it checks for each order, but as I mentioned in my pm you may need to add an index column in Power Query for other data. Below is a picture with your new data showing the correct results.
#1 I would like to suggest that you mention you would like this in m language in the future in any post. Folks post their questions all over this board. In any case perhaps we can ask ImkeF the magician of m if this can be done in m.
Here is my pbix for this post
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πare nice too.
Nathaniel
Item #1,
Hello
i have to write this to prevent somebody other again loosing time
this is again going to be ridiculous.
I tried to help to the same topic, lost time after time to only understand at the end that some "minor" issues were not mentioned.
I made the same proposal as Nathaniel_C, and neither works.
So if somebody will help here, consider, that this was already treated in very detail within here link
Good luck to whom that still is willing to help
Anonymous- please, don't opend a topic twice.
Bye
Jimmy