|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- let
- 源 = Excel.Workbook(File.Contents("C:\Users\飞飞\Desktop\VBA\提列及表名.xls"), null, true),
- 筛选的行 = Table.SelectRows(源, each ([Name] <> "当月缴费人员" and [Name] <> "当月钲费变更" and [Name] <> "说明")),
- 已添加自定义 = Table.AddColumn(
- 筛选的行,
- "自定义",
- each Table.SelectColumns(
- Table.SelectRows(
- Table.PromoteHeaders(Table.Skip([Data])),
- each not Text.Contains([姓名], "合")
- ),
- {"姓名", "应缴费额"}
- )
- ),
- 删除的列 = Table.RemoveColumns(已添加自定义, {"Data"}),
- #"展开的“自定义”" = Table.Buffer(Table.ExpandTableColumn(删除的列, "自定义", {"姓名", "应缴费额"}, {"姓名", "应缴费额"})),
- 更改的类型 = Table.TransformColumnTypes(#"展开的“自定义”", {{"应缴费额", type number}}),
- 分组的行 = Table.Group(更改的类型, {"姓名"}, {{"all", each _}}),
- 已添加自定义1 = Table.AddColumn(
- 分组的行,
- "自定义",
- each Table.AddColumn([all], "分组", each if Text.Contains(_[Name], "个") then 1 else 2)
- ),
- 已添加自定义2 = Table.AddColumn(已添加自定义1, "自定义.1", each Table.Group([自定义], "分组", {"data", each _})),
- 删除的列1 = Table.RemoveColumns(已添加自定义2, {"all", "自定义"}),
- #"展开的“自定义.1”" = Table.ExpandTableColumn(删除的列1, "自定义.1", {"data"}, {"data"}),
- 已添加自定义3 = Table.AddColumn(#"展开的“自定义.1”", "自定义", each List.Sum([data][应缴费额])),
- 已添加自定义4 = Table.AddColumn(
- 已添加自定义3,
- "自定义.1",
- each Table.FromRows(
- List.Combine(
- {
- Table.ToRows([data]),
- {
- {
- if Text.Contains([data][Name]{0}, "个") then "个人缴费" else "公司缴费",
- "",
- [自定义],
- ""
- }
- }
- }
- )
- )
- ),
- 删除的其他列 = Table.SelectColumns(已添加自定义4, {"姓名", "自定义.1"}),
- #"展开的“自定义.1”1" = Table.ExpandTableColumn(
- 删除的其他列,
- "自定义.1",
- {"Column1", "Column3"},
- {"Column1", "Column3"}
- ),
- 已透视列 = Table.Pivot(
- #"展开的“自定义.1”1",
- List.Distinct(#"展开的“自定义.1”1"[Column1]),
- "Column1",
- "Column3",
- List.Sum
- ),
- 已添加自定义5 = Table.AddColumn(已透视列, "总计", each [个人缴费] + [公司缴费]),
- 自定义1 = {"总计"}
- & List.Transform(List.Skip(Table.ToColumns(已添加自定义5)), each List.Sum(List.RemoveNulls(_))),
- 自定义2 = Table.FromRows(Table.ToRows(已添加自定义5) & {自定义1}, Table.ColumnNames(已添加自定义5))
- in
- 自定义2
复制代码 |
|