0

initial situation:

I want to count the different content of a column (B) in conjunction with a condition in another column (A) (if ="X"). So far (without condition) I count the different contents as follows:

SUMPRODUCT(($B$2:$BJ$11<>"")/COUNTIF($B$2:$BJ$11;$B$2:$B$11 &""))

enter image description here

question:

How can I include the condition from column A in the existing formula?

2 Answers 2

1

Using SUMPRODUCT( )

enter image description here


• Formula used in cell B13

=SUMPRODUCT(IFERROR((A2:A11="X")/COUNTIFS(B2:B11,B2:B11,A2:A11,"X"),""))

Instead of IFERROR( ), using IF( ) within SUMPRODUCT( ).

enter image description here


• Formula used in cell B13

=SUMPRODUCT(IF($A$2:$A$11="X", 1/(COUNTIFS($A$2:$A$11, "X", $B$2:$B$11, $B$2:$B$11)), 0))

Caveat: While exiting the edit mode one needs to hit CTRL+SHIFT+ENTER if not using MS365


11
  • Thank you for the solution that works as requested. I would like to include TRIM-function so that cells with spaces and empty cells are not counted. Should I ask a new question for this or can you give me a hint where I would have to add this?
    – user22372000
    Aug 31 at 18:32
  • 2
    @nerdyitguy can you try this once and let me know : =SUMPRODUCT(IF(($A$2:$A$11="X")*(TRIM($B$2:$B$11)<>""), 1/(COUNTIFS($A$2:$A$11, "X", $B$2:$B$11, $B$2:$B$11)), 0)) Aug 31 at 18:33
  • 1
    Perfect! Thank you your suggestion does exactly what I had hoped! You're right, there could be more than one space between the first and last name of a customer and thus differ. Is there also a possibility for this?
    – user22372000
    Aug 31 at 20:00
  • 2
    @nerdyitguy another way without helper : =SUMPRODUCT(IFERROR(((A2:A11="X")*(TRIM(B2:B11)<>""))/COUNTIFS(A2:A11,"X",B2:B11,LEFT(TRIM(B2:B11),FIND(" ",TRIM(B2:B11))-1)&"*"),0)) try this one and let me know as well Aug 31 at 20:54
  • 1
    Thank you so much!!! Everything works as desired. A real dream.
    – user22372000
    Sep 1 at 16:50
0

Here comes two options.

Use it as array formual (Ctrl+Shift+Enter, if you use early version (not Excel 365).

=SUM(IF(A2:A11="X", 1/COUNTIFS(B2:B11, B2:B11, A2:A11, "X")))


Excel 365 has a new formula UNIQUE which makes it eaiser to get the unique list.

=SUM(--ISTEXT(UNIQUE(IF(A2:A11="X",B2:B11,0))))

enter image description here

1
  • 1
    Thank you for your suggested solution. However, I prefer to use the one with IFERROR, because this way also empty cells are preventively taken into account.
    – user22372000
    Aug 31 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.