请教大神们,希望将如下表中的“下划线”,“对勾”,“叉”的内容按照这三类合并成为三列显示的表格,如何操作?感谢
请教大神们,希望将如下表中的“下划线”,“对勾”,“叉”的内容按照这三类合并成为三列显示的表格,如何操作?感谢
若不考虑源表第二列的:
Table.FromColumns(List.Split(源[Column1.1],3))
如果是按第二列,每三行一组,然后三行变三列再加上分组的列,如下显示
let
源 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMs7JLElV0skrzcmJ1YlW8krMy84vy0xW0lHyzcxJzFMCCQYUZeYlZxYk5iDUoWnzTSwqzkjMASpQck/NT0srSq2E6EwsKslLLcKuLxYA"),Compression.Deflate)),let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1.1 = _t, Column1.2 = _t]),
三行拆分 = List.Transform(Table.Split(源,3),each #table({"Column1.2","col2","col3","col4"},{List.FirstN(List.Combine({{_[Column1.2]{1}?}, _[Column1.1]&{null,null}}),4)})),
合并 = Table.Combine(三行拆分)
in
合并
再次分析题主的意思,估计是按第一列3开头的为分组开始拆分,则首列可变为
= List.Accumulate(源[Column1.1],{""},(s,c)=>if Text.At(c,0)="3" then s&{{c}} else List.RemoveLastN(s,1)&{List.Last(s)&{c}}),进而有
let
源 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY1BCoRADAT/kvPcfIS4MKCehMFDcKMGQ0biKPj7VRSEBY/dVHWHAJlwInC6irQuwAd1iht34MCzoMJZlsba8YzycH+aR1tGlAOAnGLfG+2XiZaU7NXLfNE8qVp31OHYqOP9Swt/SdONtD8="),Compression.Deflate))),
合并列 = Table.CombineColumns(源,Table.ColumnNames(源),each Text.Combine(_,"-"),"合并"),
分组 = List.Skip(List.Accumulate(合并列[合并],{""},(s,c)=>if Text.At(c,0)="3" then s&{{c}} else List.RemoveLastN(s,1)&{List.Last(s)&{c}})),
修正 = List.Transform(分组,each if List.Count(_)<3 then List.FirstN(_&{null,null},3) else _),
转换 = Table.FromRows(修正,{"Col1","Col2","Col3"}),
按分隔符拆分列 = Table.SplitColumn(转换, "Col2", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Col2.1", "Col2.2"}),
更改的类型 = Table.TransformColumnTypes(按分隔符拆分列,{{"Col2.1", type text}, {"Col2.2", type text}})
in
更改的类型
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
合并 = Table.CombineColumns(源,Table.ColumnNames(源),each Text.Combine(,"-"),"合并"),
分组 = Table.Combine(
Table.Group(合并,"合并",
{"a",each
Table.FromColumns(
List.Transform(
List.Combine(List.Transform([合并],(x)=>Text.Split(x,"-"))),
each {})
)
},
0,(x,y)=>Number.From(Text.StartsWith(y,"3"))
)[a])
in
分组
参考思路:用Table.Group的第五个参数进行分组,再把合并的列拆分,整合成表即可。