如何将表中的一列转换成多列?
有尝试用Table.TransformColums加Record.FromList,但是在Record.FromList被报错。
如何将表中的一列转换成多列?
有尝试用Table.TransformColums加Record.FromList,但是在Record.FromList被报错。
fyi...
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
变 = Table.Combine(
Table.ToList(源,each [ a = List.Transform(Text.Split(_{2},"#(lf)"),(x)=>Text.Start(x,2)),
b = List.Count(a),
c = List.Repeat({Number.From(Text.Select(_{1},{"0".."9","."}))/b},b),
d = #table({"运单号"}&a,{{_{0}}&c}) ] [d] )
),
结 = let t=Table.ColumnNames(变)
in 变 &
#table( t,
{ {"合计"}
&
List.Transform( List.Skip(t),
each List.Sum( Table.Column(变,_) )
) } )
in
结
请帮忙纠错与去除冗余步骤。谢谢!
为什么我用以下步骤后,A7077565的结果会出错呢?具体步骤如下:
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
转换 = Table.TransformColumns(源,{"应判责任部门", each Table.FromList(Text.Split(,"#(lf)"))}),
展开 = Table.ExpandTableColumn(转换, "应判责任部门", {"Column1"}, {"应判责任部门"}),
数字 = Table.AddColumn(展开, "金额", each try Text.Remove([理赔金额], {Text.Remove( [理赔金额], {"0".."9"})}) otherwise null),
中文 = Table.AddColumn(数字, "部门", each Text.Start([应判责任部门],2)),
更改 = Table.TransformColumnTypes(中文,{{"金额", type number}}),
删除 = Table.RemoveColumns(更改,{"理赔金额", "应判责任部门"}),
分组 = Table.Group(删除, {"运单号"}, {{"计数", each Table.RowCount(), type number}}),
自定义1 = Table.NestedJoin(删除,"运单号",分组,"运单号","A",JoinKind.LeftOuter),
"展开的“A”" = Table.ExpandTableColumn(自定义1, "A", {"计数"}, {"计数"}),
已添加条件列 = Table.AddColumn(#"展开的“A”", "最后金额", each if [计数] = 1 then [金额] else [金额]/2),
删除的列 = Table.RemoveColumns(已添加条件列,{"金额", "计数"}),
已透视列 = Table.Pivot(删除的列, List.Distinct(删除的列[部门]), "部门", "最后金额", List.Sum)
in
已透视列
Text.Remove错了,直接移除“元”不就可以了,你这样的结果还有个小数点在,所以错了
fyi...
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
变 = Table.Combine(
Table.ToList(源,each [ a = List.Transform(Text.Split(_{2},"#(lf)"),(x)=>Text.Start(x,2)),
b = List.Count(a),
c = List.Repeat({Number.From(Text.Select(_{1},{"0".."9","."}))/b},b),
d = #table({"运单号"}&a,{{_{0}}&c}) ] [d] )
),
结 = let t=Table.ColumnNames(变)
in 变 &
#table( t,
{ {"合计"}
&
List.Transform( List.Skip(t),
each List.Sum( Table.Column(变,_) )
) } )
in
结
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
转换 = Table.Combine(Table.AddColumn(源,"判断",each Table.FromRecords([A=Text.Split([应判责任部门],"#(lf)"),B=List.Count(A),C=Number.From(Text.Remove([理赔金额],"元")),D=if B>1 then List.Combine(List.Transform({0..B-1},(x)=>{[运单号=[运单号],部门=Text.Start(A{x},2),金额=C/B]})) else {[运单号=[运单号],部门=Text.Start(A{0},2),金额=C]}][D]))[判断]),
透视 = Table.Pivot(转换, List.Distinct(转换[部门]), "部门", "金额", List.Sum),
合计 = 透视& #table(Table.ColumnNames(透视),{{"合计"}&List.Transform(Table.ToColumns(Table.RemoveColumns(透视,"运单号")),each List.Sum(_))})
in
合计
感谢 飞天蓝球 和 KLZB 二位的精彩解决。飞天蓝球的解题方法特棒,谢谢!
提取部门直接透视