本帖最后由 mykitami 于 2024-11-6 12:58 编辑
写的有些长了点,但道理却很简单(主要是为了模仿数据透视表的样子)
汇总行进行了条件格式设置,字体加粗。
数据可以的扩展6万行,不够可以改为更大数。
=LET(ht,HSTACK(底表数据!A2:B60000,底表数据!E2:E60000),qd,TOROW(UNIQUE(TOCOL(底表数据!D2:D60000,1))),zt,HSTACK(底表数据!F2:F60000,(底表数据!D2:D60000=qd)*底表数据!F2:F60000),data,DROP(GROUPBY(ht,zt,SUM,0,3,,(底表数据!C2:C60000=B1)*(ISNUMBER(MATCH(底表数据!E2:E60000,"品类"&{1;2;3},)))),-1),fx,LAMBDA(hb,MAP(hb,SEQUENCE(ROWS(hb)),LAMBDA(x,y,IFS(x="","",SUM(1*(TAKE(hb,y)=x))=1,x,SUM(1*(TAKE(hb,y)=x))=SUM(1*(hb=x)),x&"汇总",1,"")))),qy,DROP(GROUPBY(ht,底表数据!F2:F60000,SUM,0,3,,(底表数据!C2:C60000=EDATE(B1,-12))*(ISNUMBER(MATCH(底表数据!E2:E60000,"品类"&{1;2;3},)))),-1),_qy,XLOOKUP(BYROW(DROP(qy,,-1),CONCAT),BYROW(TAKE(data,,3),CONCAT),TAKE(qy,,-1),""),VSTACK(HSTACK(底表数据!A1:B1,底表数据!E1,"Total("&TEXT(B1,"m.d")&")","去年同期Total("&TEXT(B1,"m.d")&")",qd),HSTACK(fx(INDEX(data,,1)),fx(INDEX(data,,2)),CHOOSECOLS(data,3,4),_qy,DROP(data,,4))))
|