COUNTIFS Assistance with Duplicate Values & Multiple Criteria

brandon12

New Member
Joined
Sep 12, 2018
Messages
32
https://drive.google.com/open?id=1eqtXSg4kU9vIpss9uc6VUs6mVnzVHHDmStruggling to figure out accurate formulas to return the results I'm looking for. I have attached a spreadsheet for review.

I want this data to provide three values in G4, H4, & I4:

1) The total # of DA's in column C... I'm using: =COUNTIF(C:C,"DA")

2) The total # of occurrences of exactly 1 Service Type "DA" and 1 Service Type "THER NOTE" for the same Client (summing all occurences into one cell).

3) The total # of occurrences of exactly 1 Service Type "DA" and 2 or more Service Type "THER NOTE's" for the same Client (summing all occurrences into one cell).

The result should be:

1) 5

2) 2

3) 2
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Cross posted https://www.excelforum.com/excel-fo...h-duplicate-values-and-multiple-criteria.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
H4:

Rich (BB code):
=SUMPRODUCT(--(MATCH(B2:B13,B2:B13,0)=ROW(B2:B13)-ROW(B2)+1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"DA")=1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"THER NOTE")=1))

i4:

Rich (BB code):
=SUMPRODUCT(--(MATCH(B2:B13,B2:B13,0)=ROW(B2:B13)-ROW(B2)+1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"DA")=1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"THER NOTE")>1))
 
Last edited:
Upvote 0
Eric,

I attempted to modify your formula to encompass more than the 13 rows. The following is my modification but I'm getting a #N/A error:

=SUMPRODUCT(--(MATCH(B2:B,B2:B,0)=ROW(B2:B)-ROW(B2)+1),--(COUNTIFS(B2:B,B2:B,C2:C,"DA")=1),--(COUNTIFS(B2:B,B2:B,C2:C,"THER NOTE")>1))

Any suggestions on how to alleviate this problem as I'm using this formula in many spreadsheets with 1,000 or more rows (none of which will be the same length). Is it a $ issue? Thanks!




H4:

Rich (BB code):
=SUMPRODUCT(--(MATCH(B2:B13,B2:B13,0)=ROW(B2:B13)-ROW(B2)+1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"DA")=1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"THER NOTE")=1))

i4:

Rich (BB code):
=SUMPRODUCT(--(MATCH(B2:B13,B2:B13,0)=ROW(B2:B13)-ROW(B2)+1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"DA")=1),--(COUNTIFS(B2:B13,B2:B13,C2:C13,"THER NOTE")>1))
 
Upvote 0
Correction: I meant to ask is it a #N/A error?


Eric,

I attempted to modify your formula to encompass more than the 13 rows. The following is my modification but I'm getting a #N/A error:

=SUMPRODUCT(--(MATCH(B2:B,B2:B,0)=ROW(B2:B)-ROW(B2)+1),--(COUNTIFS(B2:B,B2:B,C2:C,"DA")=1),--(COUNTIFS(B2:B,B2:B,C2:C,"THER NOTE")>1))

Any suggestions on how to alleviate this problem as I'm using this formula in many spreadsheets with 1,000 or more rows (none of which will be the same length). Is it a $ issue? Thanks!
 
Upvote 0
The problem is that you can't define a range like B2:B. You could just use a whole column reference, like B:B,

=SUMPRODUCT(--(MATCH(B:B,B:B,0)=ROW(B:B)),--(COUNTIFS(B:B,B:B,C:C,"DA")=1),--(COUNTIFS(B:B,B:B,C:C,"THER NOTE")>1))

but I'd highly discourage that. It will be very inefficient, and if you have a lot of them, it will slow down your sheet a lot. Safer to figure out the maximum row, say 4000, and use a range of B2:B4000. And depending on how many copies of the formula you have, and if you want to copy/drag them, you may need to add some $ signs.
 
Upvote 0
You were correct. Using the B:B column reference is extremely inefficient.

I attempted to plug in a range of B2:B4000 but that did not work as I received the #N/A error. I then attempted to inlude the $ as suggested but still received the same #N/A error. The following is the updated formula I used (I did insert an additional column in A which shifted my formula data one column right - B:B is now C:C):

=SUMPRODUCT(--(MATCH($C$2:$C$4000,$C$2:$C$4000,0)=ROW($C$2:$C$4000)-ROW(C2)+1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"DA")=1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"THER NOTE")>1))

Thoughts?



The problem is that you can't define a range like B2:B. You could just use a whole column reference, like B:B,

=SUMPRODUCT(--(MATCH(B:B,B:B,0)=ROW(B:B)),--(COUNTIFS(B:B,B:B,C:C,"DA")=1),--(COUNTIFS(B:B,B:B,C:C,"THER NOTE")>1))

but I'd highly discourage that. It will be very inefficient, and if you have a lot of them, it will slow down your sheet a lot. Safer to figure out the maximum row, say 4000, and use a range of B2:B4000. And depending on how many copies of the formula you have, and if you want to copy/drag them, you may need to add some $ signs.
 
Upvote 0
The only thing I see offhand is that

-ROW(C2)+1

should be

-ROW($C$2)+1

but that shouldn't matter unless you copy and/or drag the formula, or add/delete rows. Other than than, I don't know what to say. If you could show a cut-down sample, it would help.
 
Upvote 0
I've posted a sample of the data below.

Formulas are as follows (Both of these formulas are returning the #N/A value):

DA + 1 Ther Note:

=SUMPRODUCT(--(MATCH($C$2:$C$4000,$C$2:$C$4000,0)=ROW($C$2:$C$4000)-ROW($C$2)+1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"DA")=1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"THER NOTE")=1))

DA + 2 or more Ther Notes:

=SUMPRODUCT(--(MATCH($C$2:$C$4000,$C$2:$C$4000,0)=ROW($C$2:$C$4000)-ROW($C$2)+1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"DA")=1),--(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"THER NOTE")>1))

Sample Data Set:

Service IDService DateClientNameService TypeCPT CodeLocationStaff Name
1234564/5/2018Test, MiaDA90791ABCSmith, Joe
1234571/31/2018Test, ScottDA90791ABCSmith, Joe
1234582/7/2018Test, ScottTHER NOTE90834ABCSmith, Joe
1234592/22/2018Test, ScottTHER NOTE90834ABCSmith, Joe
1234603/8/2018Test, ScottTHER NOTE90834ABCSmith, Joe
1234614/12/2018Test, AngieDA90791ABCSmith, Joe
1234625/17/2018Test, AngieTHER NOTE90834ABCSmith, Joe
1234636/21/2018Test, JohnDA90791ABCSmith, Joe
1234647/26/2018Test, JohnTHER NOTE90834ABCSmith, Joe
1234658/30/2018Test, JaneDA90791ABCSmith, Joe
12346610/4/2018Test, JaneTHER NOTE90834ABCSmith, Joe
12346711/8/2018Test, TomDA90791ABCSmith, Joe

<colgroup><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>



The only thing I see offhand is that

-ROW(C2)+1

should be

-ROW($C$2)+1

but that shouldn't matter unless you copy and/or drag the formula, or add/delete rows. Other than than, I don't know what to say. If you could show a cut-down sample, it would help.
 
Upvote 0
The MATCH generates errors if you have empty rows. You can try this:

Code:
=SUM(IFERROR(MATCH($C$2:$C$4000,$C$2:$C$4000,0)=ROW($C$2:$C$4000)-ROW($C$2)+1,0)*(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"DA")=1)*(COUNTIFS($C$2:$C$4000,$C$2:$C$4000,$D$2:$D$4000,"THER NOTE")[COLOR=#ff0000]=[/COLOR]1))

confirmed with Control+Shift+Enter. Change the last = to > for the other formula.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top