目标:按客户所需日期列出的产品来计算运行需求,以了解哪些订单可以发货,以及库存在什么时候(未来日期)不支持未结订单。
数据:针对Microsoft SQL DB的Microsoft查询返回MS Excel表,其中包含按行项目定单和手头的起始数量。
订单可以是任意数量的900种不同产品的混合搭配。
数据是先进先出的(按所需日期排序)。每天刷新一次查询,即可完成完整的订单号或特定的订单项,并退出表格。当新订单到达时,它们将显示在表格中(底部)。总体而言,有900种产品随时带有大约1100个未清订单项。
ORDER # | DESIRED DATE| PRODUCT | QTY DUE | REM ON HAND | Cum Dmd
CO-32 | 1/3/19 | Ducks | 2 | 5 | 100 (all open orders)
CO-32 | 1/3/19 | Chick | 100 | 3 | 100
CO-33 | 1/7/19 | Ducks | 2 | 3 | 102
CO-33 | 1/7/19 | CatsA | 5 | 15| 10
CO-33 | 1/8/19 | Chick | 10 | -7 | 110
CO-34 | 1/8/19 | CatsA | 2 | 13 | 12
CO-35 | 2/10/19| DogsA | 25 | 100 | 125
CO-35 | 2/10/19| Ducks | 25 | -22 | 127
当前问题:
(A)以下结果查询结果代码带有一个新选项卡,即新表会丢失行-仅返回约677行原始1105个订单项订单。
(B)查询中的代码将锁定客户端处理器4-5分钟以循环遍历数据集。
当前代码:
let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"PART", type text}, {"QTY DUE", Int64.Type}}),
AddIndex = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1),
RunTotal = Table.AddColumn(AddIndex, "Cum Dmd", each let PART=[PART], Index=[Index]
in
List.Sum(Table.SelectRows(AddIndex,
each [Index]<=Index and [PART]=PART)[QTY DUE])),
#"Removed Columns" = Table.RemoveColumns(RunTotal,{"Index"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "Remain QOH", each [T ON HAND]-[Cum Dmd]),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"ORDER", "CUSTOMER", "PART", "MISC_REFERENCE", "QTY DUE", "Remain QOH", "T ON HAND", "T Demand", "ORDER QTY", "SHIPPED QTY", "Customer DESIRE", "PROMISE", "Order Date", "ENTERED_BY", "Age", "Cum Dmd"})
in
#"Reordered Columns"