[英]Countif with Merged Cells in excel
I have the below table.我有下表。 From this, I would like to get the count of the subject each class has as shown in Column F using a function. Like as how many subjects we have in Class A, how many subjects we have in Class B, and so on.
由此,我想使用 function 来计算每个 class 的主题数,如 F 列所示。就像我们在 Class A 中有多少个主题,在 Class B 中有多少个主题,等等。
I used the COUNTIF formula, but it didn't work because of the merged cells.我使用了 COUNTIF 公式,但由于单元格合并,它不起作用。
Is it possible to get the count of the subjects keeping the merged cells?是否有可能获得保留合并单元格的主题的数量?
One way of doing this could be through REDUCE()
:一种方法是通过
REDUCE()
:
Formula in D1
: D1
中的公式:
=LET(a,SCAN(A2,A2:A21,LAMBDA(a,b,IF(b="",a,b))),REDUCE(A1:B1,UNIQUE(a),LAMBDA(b,c,VSTACK(b,HSTACK(c,SUM(--(a=c)))))))
Note that SCAN()
acts like a filldown function. Also note that merged cells are evil!请注意
SCAN()
的作用类似于填充 function。还要注意合并的单元格是邪恶的!
=LET(a,A2:A21,
c,DROP(REDUCE(0,a,LAMBDA(x,y,VSTACK(x,IF(y="",TAKE(x,-1),y)))),1),
u,UNIQUE(c),
m,MMULT(--(TRANSPOSE(c)=u),SEQUENCE(COUNTA(c),,1,0)),
HSTACK(u,m))
Where c
creates the unmerged equivalent of column A replacing blanks with the value above and m
creates the count for each value that equals the unique values u
in the unmerged version of column A.其中
c
创建 A 列的未合并等价物,用上面的值替换空白, m
为每个值创建等于 A 列未合并版本中唯一值u
的计数。
Edit: as Mayukh commented we could replace MMULT by MAP/SUM:编辑:正如 Mayukh 评论的那样,我们可以用 MAP/SUM 替换 MMULT:
=LET(a,A2:A21,
c,DROP(REDUCE(0,a,LAMBDA(x,y,VSTACK(x,IF(y="",TAKE(x,-1),y)))),1),
u,UNIQUE(c),
HSTACK(u,MAP(u,LAMBDA(x,SUM(--(c=x))))))
Here is another way using MAP()
这是使用
MAP()
的另一种方法
• Formula used in cell D2
• 单元格
D2
中使用的公式
=LET(a,LOOKUP(ROW(A2:A21),ROW(A2:A21)/(A2:A21<>""),A2:A21),
b,UNIQUE(a),
c,MAP(b,LAMBDA(x,SUM(--(x=a)))),
VSTACK(A1:B1,HSTACK(b,c)))
We can use SCAN()
as well, since JvdV Sir has already shown that option, hence using the OLDSCHOOL Function LOOKUP()
.我们也可以使用
SCAN()
,因为JvdV Sir 已经显示了该选项,因此使用OLDSCHOOL Function LOOKUP()
。 Which simply does the same thing as shown using SCAN()
refer the screenshot below,它只是做与使用
SCAN()
所示相同的事情,请参考下面的屏幕截图,
• Using SCAN()
• 使用
SCAN()
=SCAN(A2:A21,A2:A21,LAMBDA(x,y,IF(y="",x,y)))
• Using LOOKUP()
• 使用
LOOKUP()
=LOOKUP(ROW(A2:A21),ROW(A2:A21)/(A2:A21<>""),A2:A21)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.