|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
PQ 解决。
就是一个体力活。。。。。。。。。
- let
- 源 = Excel.CurrentWorkbook(){[Name = "表1"]}[Content],
- Unpivot = Table.UnpivotOtherColumns(源, {"姓名", "险种"}, "属性", "值"),
- Com = Table.CombineColumns(
- Unpivot,
- {"属性", "险种"},
- Combiner.CombineTextByDelimiter("-", QuoteStyle.None),
- "已合并"
- ),
- Pivot = Table.Pivot(Com, List.Distinct(Com[已合并]), "已合并", "值", List.Sum),
- Tab1 = Table.DemoteHeaders(Pivot),
- Tab2 = List.Accumulate(
- List.Skip(Table.ColumnNames(Tab1)),
- Tab1,
- (x, y) =>
- Table.ReplaceValue(
- x,
- "",
- "",
- (o, p, q) => if Text.Contains(Text.From(o), "-") then Text.Split(o, "-") else o,
- {y}
- )
- ),
- Tab3 = Table.TransformColumns(
- Table.Transpose(Tab2),
- {"Column1", each if _ = "姓名" then {_, ""} else _}
- ),
- Tran = Table.TransformColumns(
- Tab3,
- {"Column1", each Text.Combine(List.Transform(_, Text.From), "-"), type text}
- ),
- Tab4 = Table.SplitColumn(
- Tran,
- "Column1",
- Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv),
- {"Column1.1", "Column1.2"}
- ),
- Group1 = Table.Group(Tab4, List.First(Table.ColumnNames(Tab4)), {"Data", each _})[Data],
- Sum1 = {List.First(Group1)}
- & List.Transform(
- List.Skip(Group1),
- each [
- a = Table.Group(
- _,
- {},
- List.Transform(
- List.Skip(Table.ColumnNames(_)),
- (x) => {
- x,
- (y) =>
- try
- List.Sum(List.Transform(Table.Column(_, x), (z) => Number.From(z)))
- otherwise
- "小计"
- }
- )
- ),
- b = _ & a
- ][b]
- ),
- Tab5 = Table.Combine(List.Transform(List.Skip(Sum1), each Table.LastN(_, 1))),
- Sum2 = Table.Group(
- Tab5,
- {},
- List.Transform(
- List.Skip(Table.ColumnNames(Tab5)),
- each {_, (x) => try List.Sum(Table.Column(Tab5, _)) otherwise "合计"}
- )
- ),
- Tab6 = Table.Combine(Sum1 & {Sum2}),
- Tran2 = Table.Transpose(Tab6),
- Res = Tran2
- & Table.Group(
- Tran2,
- {},
- List.Transform(
- Table.ColumnNames(Tran2),
- each {_, (x) => try List.Sum(List.Skip(Table.Column(Tran2, _), 2)) otherwise "总计"}
- )
- )
- in
- Res
复制代码
|
-
|