|
这种涉及相邻行(更准确的说是递归)计算的问题,还是公式更为简洁易懂。
PQ写出来就比较难看了
- let
- Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY1LDoAgDETv0jVJP3yEpXoMwv2vYauCGDaTaV8yr1bYwQEjBRQSsU6kWQiaq3BolYjkjdrfW0ieaEISpVzsWHFGSoazHmGm5+ONw3vvc/ioiaWLy0LTu1z68o+qd+tejgO3Cw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Date = _t, Qty = _t, Split = _t]),
- #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Date", type date}, {"Qty", Int64.Type}, {"Split", Int64.Type}}),
-
- #"Split by Code" = Table.Group(
- #"Changed Type",
- "Code",
- {"Grp", each
- let
- split = [Qty],
- total = [Split]{0},
- arr = List.Accumulate({0..Table.RowCount(_)-1}, {}, (s,c) => let remain = total-(List.Sum(s)??0)
- in
- if remain >= split{c} then s&{split{c}} else s&{remain}) in Table.FromColumns(Table.ToColumns(_) & {arr}, Table.ColumnNames(Source) & {"Arrangement"})
- }
- ),
- #"Expanded Grp" = Table.ExpandTableColumn(#"Split by Code", "Grp", {"Date", "Qty", "Split", "Arrangement"})
- in
- #"Expanded Grp"
复制代码
|
|