我有一些条形码扫描仪,它可以列出 Excel 中某一列上的代码。
目标是根据下面的测试用例将原始列划分为表。有人知道如何实现它吗?
表之前:
之后的表:
我尝试过使用 Power 查询,但想使用 Excel 函数来实现。尝试使用 WRAPROWS
=WRAPROWS(A2:A300,4)
不工作。还有一个问题,当A、B、C列的数量是两倍时,它会相加。例如,如丝网打印中所示。
如果您有任何疑问,请随时询问。如果需要的话我会发布电源查询代码。 TIA。
let
Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([A], "XXID") then [A] else null),
#"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([A], "UID")),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom.1", each if Text.Length([A]) = 5 then [A] else null),
#"Filled Down1" = Table.FillDown(#"Added Custom",{"Custom.1"}),
#"Added Custom1" = Table.AddColumn(#"Filled Down1", "Custom.2", each if Text.Length([A]) = 6 then [A] else null),
#"Filled Down2" = Table.FillDown(#"Added Custom1",{"Custom.2"}),
#"Filled Up" = Table.FillUp(#"Filled Down2",{"Custom.2"}),
#"Added Custom2" = Table.AddColumn(#"Filled Up", "Custom.3", each if Text.Length([A]) < 4 then [A] else null),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each [Custom.3] <> null and [Custom.3] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Custom.3"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Custom.1", "Custom.2", "A"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Custom", type text}, {"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}, {"A", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Custom", "Custom.1", "Custom.2"}, {{"A", each List.Sum([A]), type nullable text}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Grouped Rows",{{"Custom", type text}, {"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}, {"A", type number}})
in
#"Changed Type2"
最佳答案
尝试:
=LET(arr,VSTACK(TOCOL(A:A,1),"Finish"),n,ROWS(arr),seq,SEQUENCE(n),seqA,SEQUENCE(n-1),
WRAPROWS(DROP(REDUCE("",seqA,LAMBDA(all,curr,
LET(length,LEN(INDEX(arr,curr)),lenNext,LEN(INDEX(arr,curr+1)),IF(AND(length<=4,lenNext>4),VSTACK(all,
XLOOKUP(1,(LEN(arr)=8)*(seq<curr),arr,,,-1),
XLOOKUP(1,(LEN(arr)=5)*(seq<curr),arr,,,-1),
XLOOKUP(1,(LEN(arr)=6)*(seq<curr),arr,,,-1),
SUM(FILTER(arr,(seq<=curr)*(seq>XMATCH(1,(LEN(arr)>4)*(seq<curr),,-1))))
),all)))),1),4))
关于Excel:将一列划分为具有多个条件的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76301916/