Count duplicate cell values as one if multiple criteria are met

爱⌒轻易说出口 提交于 2019-12-11 05:56:42

问题


I am trying to get the total count of entries per month based on the status ("Settled") and the distinct code. If the other status of the other entries in that certain code is not yet settled, it shouldn't count. Please see example below and the expected output.

MONTH   |CODE  |CONTRIBUTION|STATUS
JANUARY |CS-111|500         |Settled
JANUARY |CS-111|500         |Settled
FEBRUARY|CS-131|200         |Settled    
FEBRUARY|CS-131|200         |Waiting
FEBRUARY|CS-141|300         |Settled
MARCH   |CS-151|400         |Waiting
MARCH   |CS-161|700         |Settled

Sample output:

January  | 1  | 1 because same code and status
February | 1  | 1 because only CS-141 is settled, the second entry of CS-131 is Waiting
March    | 1  | 1 because only CS-161 is settled

This is my formula based on this question:

=SUMPRODUCT(--($A$2:$A$8="January"),--(COUNTIFS($A$2:$A$8,$A$2:$A$8,$B$2:$B$8,$B$2:$B$8,$D$2:$D$8,"Settled")=0))

With the formula above, I get 2 as the output for January and not 1. 1 because they have the same code and status. Could you kindly help me which concept I should apply to get the expected output? Hope my question is clear. Thank you very much.

Apologies if this question has been asked before.


回答1:


Imagine this setup:

Formula in G2:

=SUM(--(FREQUENCY(IF(($A$2:$A$8=G2)*($D$2:$D$8="Settled"),IF(COUNTIFS($B$2:$B$8,$B$2:$B$8,$D$2:$D$8,"Waiting")=0,MATCH($B$2:$B$8,$B$2:$B$8,0))),ROW($B$2:$B$8)-ROW($B$2)+1)>0))

Note: It's an array formula and needs to be confirmed through Ctrl+Shift+Enter

Drag down...



来源:https://stackoverflow.com/questions/58797044/count-duplicate-cell-values-as-one-if-multiple-criteria-are-met

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