|
本帖最后由 cnmlgb9998 于 2024-9-19 19:27 编辑
- let
- 源 = Excel.CurrentWorkbook(){[Name = "表1"]}[Content],
- Lst = List.Accumulate(
- Table.ColumnNames(源),
- {},
- (x, y) =>
- x
- & {
- [
- a = Table.Group(
- 源,
- y,
- {
- "Data",
- each [
- a = Table.SelectColumns(
- _,
- List.Range(
- Table.ColumnNames(源),
- List.PositionOf(
- Table.ColumnNames(源),
- y
- ),
- 4
- )
- ),
- b = Table.PromoteHeaders(
- Table.Skip(
- Table.FirstN(
- a,
- (o) =>
- Record.Field(o, y)
- <> null
- )
- )
- )
- ][b]
- },
- 0,
- (m, n) =>
- Number.From(
- if n = null then
- 0
- else
- Text.Contains(Text.From(n), "销售")
- )
- ),
- b = Table.RenameColumns(
- Table.SelectRows(a, (o) => Record.Field(o, y) <> null),
- {y, "K"}
- )
- ][b]
- }
- ),
- Tab1 = Table.Distinct(Table.Combine(Lst), {"K"})[Data],
- Tab2 = Table.Combine(Tab1),
- Group = Table.Group(
- Tab2,
- {"品名"},
- {{"销售数量", each List.Sum([数量]), type number}, {"销售金额", each List.Sum([金额]), type number}}
- )
- in
- Group
复制代码
在VBA区看到的一道题。我用PQ解决了。请大家帮提点建议。
我感觉 ,这题是极有代表性的。很有成就感。感觉自己学了8个月的PQ,完全自学。
是不是已经很强了????????
|
|