再来个超长火车,基本实现楼主的想法。目前只是实现目标,没有优化。
- =LET(Xa,A2:A29,Xb,B2:B29,Xc,C2:C29,Xd,D2:D29,Xe,E2:E29,Xf,F2:F29,t,DROP(PIVOTBY(HSTACK(HSTACK(MATCH(Xb&Xd,Xb&Xd,),Xb&Xd),Xb,Xd,Xa,Xc),HSTACK(HSTACK(MATCH(Xc,{"总包","分包","采购"},),Xc),HSTACK(MATCH(Xe,{"公司名称","合同金额","开票","收款"},),Xe),Xe),1*Xf,SUM,0,2,1,0),,2),Res,VSTACK(CHOOSEROWS(t,{2,4}),DROP(t,5)),SI,VSTACK("项目",DROP(TAKE(Res,,1),1)),b,CHOOSECOLS(Res,2),sDay,VSTACK("日期",DROP(CHOOSECOLS(Res,3),1)),sType,CHOOSECOLS(Res,4),c,CHOOSECOLS(Res,{5,6,7}),d,CHOOSECOLS(Res,{8,9,10}),e,CHOOSECOLS(Res,{11,12,13}),Sz,VSTACK("总包","公司名称",DROP(IF(sType="总包",b,""),2)),Sf,VSTACK("分包","公司名称",DROP(IF(sType="分包",b,""),2)),Sc,VSTACK("采购","公司名称",DROP(IF(sType="采购",b,""),2)),sSI,MAP(SEQUENCE(ROWS(SI)),LAMBDA(x,IF(x<3,INDEX(SI,x),IF(x=ROWS(SI),"汇总",IF(INDEX(SI,x)="",INDEX(SI,x-1),INDEX(SI,x)))))),sSz,MAP(SEQUENCE(ROWS(Sz)),LAMBDA(x,IF(x<4,INDEX(Sz,x),IF(INDEX(Sz,x)<>"",INDEX(Sz,x),IF(INDEX(Sz,x-1)<>"",INDEX(Sz,x-1)&"_小计",""))))),sSf,MAP(SEQUENCE(ROWS(Sf)),LAMBDA(x,IF(x<4,INDEX(Sf,x),IF(INDEX(Sf,x)<>"",INDEX(Sf,x),IF(INDEX(Sf,x-1)<>"",INDEX(Sf,x-1)&"_小计",""))))),sSc,MAP(SEQUENCE(ROWS(Sc)),LAMBDA(x,IF(x<4,INDEX(Sc,x),IF(INDEX(Sc,x)<>"",INDEX(Sc,x),IF(INDEX(Sc,x-1)<>"",INDEX(Sc,x-1)&"_小计",""))))),sFinal,HSTACK(sSI,sDay,sSz,c,sSf,d,sSc,e),sFinal)
复制代码 |