let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
自定义1 = Table.Group(源,"产品编号",{"a",each Table.Transpose(Table.FromColumns({List.Transform(Table.Group(Table.AddColumn(Table.RemoveColumns(,"产品编号"),"期间",each Date.DayOfYear([销售日期])-Date.DayOfYear([上市日期])+1),"期间",{"b",each },0,(x,y)=>Number.From(Number.RoundUp(y/7)<>Number.RoundUp(x/7)))[b],each List.Sum([成交金额]))}))}),
自定义2 = Table.FromColumns({Table.ToColumns(自定义1){0}}&Table.ToColumns(Table.Combine(Table.ToColumns(自定义1){1})),{"产品编码"}&List.TransformMany({1..Table.ColumnCount(Table.Combine(自定义1[a]))},each {null},(x,y)=>"第"&Text.From(x)&"周"))
in
自定义2