let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
改类型 = Table.TransformColumnTypes(源,{{"上市日期", type date}, {"销售日期", type date}}),
分组 = Table.Group(改类型,"产品编号",{"a",each
[a=Table.Group(,"销售日期",{"aa",each List.Sum([成交金额])},0,
(x,y)=>Number.From(Number.RoundDown(Number.From(x-[上市日期]{0})/7,0)<>
Number.RoundDown(Number.From(y-[上市日期]{0})/7,0))),
b=Table.FromRows({a[aa]},List.Transform({1..List.Count(a[销售日期])},each Number.ToText(,"第0周")))][b]
}),
展开 = Table.ExpandTableColumn(分组,"a",List.Union(List.Transform(分组[a],each Table.ColumnNames(_))))
in
展开