本帖最后由 edwin11891 于 2024-10-14 10:35 编辑
方法1:只需要再原来的公式上判断一下行数即可:
- =LET(s,FILTER(B36:B4969,B36:B4969<>""),F,DROP(FILTER(B6:B4939,B6:B4939<>""),-30),t,IF(s/F>1.005,1,0),a,SCAN(0,SEQUENCE(ROWS(t)-1,,2),LAMBDA(x,y,IF(INDEX(t,y)=INDEX(t,y-1),x,1+x))),b,VSTACK(0,a),c,REDUCE("",UNIQUE(b),LAMBDA(x,y,VSTACK(x,LET(Sf,FILTER(s,b=y),Isone,FILTER(t,b=y),n,MATCH(MAX(Sf),Sf,0),m,MAP(SEQUENCE(ROWS(Sf)),LAMBDA(xx,IF(xx<=n,1,0))),m*(Isone=1)*(n>2))))),d,DROP(c,1),d)
复制代码
方法2:在原方法的最终结果上再处理。由于类似“01010”这种结构,需要处理两次,所以SUBSTITUTE函数连续用了两次,这样子下来公式就超长了,由于每步都定义了名称,可以逐步输出结果查看分步结果:
- =LET(s,FILTER(B36:B4969,B36:B4969<>""),F,DROP(FILTER(B6:B4939,B6:B4939<>""),-30),t,IF(s/F>1.005,1,0),a,SCAN(0,SEQUENCE(ROWS(t)-1,,2),LAMBDA(x,y,IF(INDEX(t,y)=INDEX(t,y-1),x,1+x))),b,VSTACK(0,a),c,REDUCE("",UNIQUE(b),LAMBDA(x,y,VSTACK(x,LET(Sf,FILTER(s,b=y),Isone,FILTER(t,b=y),n,MATCH(MAX(Sf),Sf,0),m,MAP(SEQUENCE(ROWS(Sf)),LAMBDA(xx,IF(xx<=n,1,0))),m*(Isone=1))))),d,DROP(c,1),e,CONCAT(0,d,0),ga,SUBSTITUTE(SUBSTITUTE(e,"010","000"),"010","000"),g,SUBSTITUTE(SUBSTITUTE(ga,"0110","0000"),"0110","0000"),h,1*DROP(DROP(TOCOL(REGEXP(g,".")),1),-1),h)
复制代码
|