题目:

左表转成右表,同一[Aircraft][Model][WheelNum]依次横向排列。
解法:
先分组,表和列之间多次转换后,展开即可。
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
分组 = Table.Group(源, {"Aircraft", "Model", "WheelNum"}, {"a", each Table.FromColumns(List.Transform(List.Combine(Table.ToRows(Table.SelectColumns(_,{"MeasureDate","Sizemm"}))),each {_}))}),
展开 = Table.ExpandTableColumn(分组, "a", Table.ColumnNames(分组{28}[a]))
in
展开
文件中,table展开后column排序乱序,用了另一笨方法
let 源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content], #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(源, {{"Sizemm", type text}}, "zh-CN"),{"MeasureDate", "Sizemm"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"), #"Grouped Rows" = Table.Group(#"Merged Columns", {"Aircraft", "Model", "WheelNum"}, {{"Count", each Text.Combine([Merged],",")}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows","Count",Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv),{"Count.1", "Count.2", "Count.3", "Count.4", "Count.5", "Count.6", "Count.7", "Count.8", "Count.9", "Count.10", "Count.11", "Count.12", "Count.13", "Count.14", "Count.15", "Count.16", "Count.17", "Count.18", "Count.19", "Count.20", "Count.21", "Count.22", "Count.23", "Count.24", "Count.25", "Count.26", "Count.27", "Count.28", "Count.29", "Count.30", "Count.31", "Count.32", "Count.33", "Count.34", "Count.35", "Count.36"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Count.1", type date}, {"Count.2", Int64.Type}, {"Count.3", type date}, {"Count.4", Int64.Type}, {"Count.5", type date}, {"Count.6", Int64.Type}, {"Count.7", type date}, {"Count.8", Int64.Type}, {"Count.9", type date}, {"Count.10", Int64.Type}, {"Count.11", type date}, {"Count.12", Int64.Type}, {"Count.13", type date}, {"Count.14", Int64.Type}, {"Count.15", type date}, {"Count.16", Int64.Type}, {"Count.17", type date}, {"Count.18", Int64.Type}, {"Count.19", type date}, {"Count.20", Int64.Type}, {"Count.21", type date}, {"Count.22", Int64.Type}, {"Count.23", type date}, {"Count.24", Int64.Type}, {"Count.25", type date}, {"Count.26", Int64.Type}, {"Count.27", type date}, {"Count.28", Int64.Type}, {"Count.29", type date}, {"Count.30", Int64.Type}, {"Count.31", type date}, {"Count.32", Int64.Type}, {"Count.33", type date}, {"Count.34", Int64.Type}, {"Count.35", type date}, {"Count.36", Int64.Type}}) in #"Changed Type"我测试的展开并没有乱序啊,而且使用Table.ColumnNames替代系统自动生成的公式,应该也不会出现乱序的吧?
看到了,我是直接在分组后,新建展开,使用遇到乱序。
但为什么我用笨方法,做出来有 36 列?
本身就是有36列,因为默认展开的公式太长了,我用Table.ColumnNames。原来写的是{0}获取第一行的标题,但是第一行只有20列,现在改成最长的一行{28},也是36列了。
明白了,原来{0}是获取第一行的标题,
还有这种操作╰( ̄▽ ̄)╭
分组后面半部分,用List.Accumulate貌似会快一点点。
横向展开可以先合并列,然后分组用Text.Combine,来合并List,再用拆分列更方便
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
合并的列 = Table.CombineColumns(Table.TransformColumnTypes(源, {{"Sizemm", type text}}, "zh-CN"),{"MeasureDate", "Sizemm"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"已合并"),
分组 = Table.Group(合并的列, {"Aircraft", "Model", "WheelNum"}, {"a", each Text.Combine(_[已合并],"/")}),
按分隔符拆分列 = Table.SplitColumn(分组, "a", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"a.1", "a.2", "a.3", "a.4", "a.5", "a.6", "a.7", "a.8", "a.9", "a.10", "a.11", "a.12", "a.13", "a.14", "a.15", "a.16", "a.17", "a.18", "a.19", "a.20", "a.21", "a.22", "a.23", "a.24", "a.25", "a.26", "a.27", "a.28", "a.29", "a.30", "a.31", "a.32", "a.33", "a.34", "a.35", "a.36"})
in
按分隔符拆分列