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
合计