|
本帖最后由 cnmlgb9998 于 2024-11-13 15:39 编辑
请大神 多多指点。如何 剪枝?减少冗余。- let
- 源 = Excel.CurrentWorkbook(),
- Data = 源{[Name = "表5"]}[Content],
- Filter = 源{[Name = "表6"]}[Content],
- fx = (x, y) =>
- [
- a = Table.SelectRows(Data, each [始发站] = x[出发]),
- b =
- if Table.IsEmpty(a) then
- y
- else
- List.Combine(
- List.Transform(
- Table.ToRecords(a),
- each
- if [终点站] = x[目的] then
- y & {{[终点站], [价格]}}
- else
- @fx(
- Record.TransformFields(
- x,
- {{"出发", (z) => [终点站]}}
- ),
- y & {{[终点站], [价格]}}
- )
- )
- )
- ][b],
- Tab = List.Transform(Table.ToRecords(Filter), each Table.FromRows(fx(_, {{[出发], 0}}))),
- Group = Table.Group(Tab{0}, "Column1", {"D", each _}, 0, (x, y) => Number.From(y = Filter[出发]{0})),
- Sele = List.Select(
- Group[D],
- each List.ContainsAll([Column1], List.Skip(Table.ToRows(Filter){0}))
- ),
- Sele2 = [
- a = List.Min(List.Transform(Sele, each List.Sum([Column2]))),
- b = List.Select(Sele, each List.Sum([Column2]) = a)
- ][b],
- Res1 = Sele2{0},
- Chang = Text.Combine(
- List.Accumulate(
- {1 .. Table.RowCount(Res1) - 1},
- {},
- (x, y) =>
- x
- & {
- Text.Format(
- "#{0}>>#{1},¥#{2}",
- {
- Text.From(Res1[Column1]{y - 1}),
- Text.From(Res1[Column1]{y}),
- Text.From(Res1[Column2]{y})
- }
- )
- }
- ),
- " | "
- )
- & " | 合计:"
- & Text.From(List.Sum(Res1[Column2])),
- Res2 = #table(1, {{Chang}})
- in
- Res2
复制代码
|
|