在excel中扩展范围

s4n0splo  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(148)

你好,我有一个Excel文件,其中包含一列的邮政编码范围

我有近7000个范围,我想扩展,以便每行有1个邮政编码。如果可能的话,保持相应的天数和服务,但如果不是,我只会很高兴与延长拉链列

fkvaft9z

fkvaft9z1#

公式:

E1中:

=REDUCE(A1:C1,ROW(A2:A6),LAMBDA(x,y,LET(z,INDEX(A:A,y),VSTACK(x,IFERROR(EXPAND(SEQUENCE(RIGHT(z,5)-LEFT(z,5)+1,,--LEFT(z,5)),,3),INDEX(A:C,y,{1,2,3}))))))

PowerQuery:

M代码:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ZipCode", type text}, {"Days", Int64.Type}, {"Service", Int64.Type}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [ZipCode], each Text.Combine(List.Transform(List.Numbers(Number.FromText(Text.Start([ZipCode],5)),1+Number.FromText(Text.Range([ZipCode],6))-Number.FromText(Text.Start([ZipCode],5))), each Number.ToText(_)),"|"),Replacer.ReplaceText,{"ZipCode"}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Replaced Value", {{"ZipCode", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "ZipCode"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"ZipCode", Int64.Type}})
in
    #"Changed Type1"

也许在PQ方面更有经验的人能够给予更好的解决方案。

相关问题