本帖最后由 edwin11891 于 2024-11-27 20:50 编辑
稍稍修改一下,避免品类实际数量少于编号行时出现空行。为便于实用,另外增加三列,本月采购次数、采购最高价、最低价。
附件文件利用条件格式设置了自动边框和填色。
- =LET(Sa,SHEETSNAME(,1,1),s,FILTER(Sa,TEXTBEFORE(Sa,".",,,,"")=M1&""),t,DROP(REDUCE("",s,LAMBDA(x,y,VSTACK(x,LET(a,INDIRECT("'"&y&"'!A1:G1000"),b,FILTER(a,TAKE(a,,1)<>""),b)))),1),SL,FILTER(SEQUENCE(ROWS(t)),ISNUMBER(FIND("【】"&P1,TAKE(t,,1)))),EL,MAP(SL,LAMBDA(x,LET(Pm,x-1+MATCH("小计",DROP(TAKE(t,,1),x),),Pn,x-1+MATCH(1=1,DROP(CHOOSECOLS(t,2)="",x),),MIN(Pm,Pn)))),Res,DROP(REDUCE("",SL&","&EL,LAMBDA(x,y,VSTACK(x,LET(a,TEXTBEFORE(y,",")*1,b,TEXTAFTER(y,",")*1,DROP(TAKE(t,b),a))))),1),SG,DROP(GROUPBY(CHOOSECOLS(Res,{2,3}),HSTACK(TAKE(Res,,-4),CHOOSECOLS(Res,{4,5,5})),HSTACK(SUM,AVERAGE,SUM,SUM,COUNT,MAX,MIN),0,0),1),SF,HSTACK(SEQUENCE(ROWS(SG)),SG),Ssum,HSTACK("","合计","",SUM(CHOOSECOLS(SG,3)),"",SUM(CHOOSECOLS(SG,5)),""),Stitle,{"序号","品名","规格","数量","单价","合计","备注","次数","最高价","最低价"},IFERROR(VSTACK(Stitle,SF,Ssum),""))
复制代码
|