Excel count unique in range if

空扰寡人 提交于 2019-12-20 07:42:31

问题


What formula can be used to count unique values in column A if Column B is a value. i have seen many online but none of them seem to work when only using Column ranges , the data will be of varied length so only column ref can be used

this worked

=SUMPRODUCT((A1:A18<>"")*(B1:B18=$D$1)/COUNTIF(A1:A18,A1:A18))

but not when changed to

=SUMPRODUCT((A:A<>"")*(B:B=$D$1)/COUNTIF(A:A,A:A))

table

  A           B         C         D          E
12/12/2015  criteria1           criteria1      3
12/12/2015  criteria1           
13/12/2015  criteria1           
13/12/2015  criteria1           
14/12/2015  criteria1           
14/12/2015  criteria1           
18/12/2015  criteria2           
19/12/2015  criteria2           
20/12/2015  criteria2           
21/12/2015  criteria2           
22/12/2015  criteria2           
23/12/2015  criteria2           
24/12/2015  criteria3           
25/12/2015  criteria3           
26/12/2015  criteria3           
27/12/2015  criteria3           
28/12/2015  criteria3           
29/12/2015  criteria3       

I Have also tried sumproduct with frequency but always got N/A


回答1:


If your data are in A1:B18, and criteria1 is in C1, try:

{=SUM(IF(FREQUENCY(IF(A1:A18<>"", IF(B1:B18=C1, MATCH(A1:A18, A1:A18, 0))), ROW(A1:A18)-ROW(A1)+1), 1))}

Expanded:

{=SUM(
    IF(
        FREQUENCY(
            IF(A1:A18<>"", 
                IF(B1:B18=C1, 
                    MATCH(A1:A18, A1:A18, 0)
                )
            ), 
            ROW(A1:A18)-ROW(A1)+1
        ), 
    1)
)}

Enter as an array formula with CtrlShiftEnter



来源:https://stackoverflow.com/questions/31255222/excel-count-unique-in-range-if

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!