优化了一下,火车减少了几个车皮:
- =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}),fy,LAMBDA(XX,VSTACK("XX","公司名称",DROP(IF(sType=XX,b,""),2))),Sz,fy("总包"),Sf,fy("分包"),Sc,fy("采购"),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)))))),fx,LAMBDA(XX,MAP(SEQUENCE(ROWS(XX)),LAMBDA(x,IF(x<4,INDEX(XX,x),IF(INDEX(XX,x)<>"",INDEX(XX,x),IF(INDEX(XX,x-1)<>"",INDEX(XX,x-1)&"_小计","")))))),sFinal,HSTACK(sSI,sDay,fx(Sz),c,fx(Sf),d,fx(Sc),e),sFinal)
复制代码 |