Counting with multiple criteria

ChuckDrago

Active Member
Joined
Sep 7, 2007
Messages
470
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone,
I have been asked to provide charts for returned merchandise by return code. I initially imagined building a table where the merchandise ID was in column "A" and column "B" will have the return codes, which are A,B,C,D,E and F. Therefore to graph the results I would need to count the occurrences by code for each merchandise ID, such as ID 12345 has 3 A's, 5 B's, no C's...etc.
I encountered a formula that appeared to do the trick but I can't make it to work. Therefore the idea is two fold:
a) Request help in making it work, or
b) If there is a simpler approach get guidelines to it.

The formula in question is

<code/> '=SUMPRODUCT((rng1 = criteria1)*(rng2=criteria2)*(SUBTOTAL(3,OFFSET(rng,rows,0,1))))</code>

I interpreted range1 to be "A2:A100", criteria1 = xxxxx (variable - each Merchandise ID), rng2 as "B2:B200" and criteria2 as ("x",variable - each return code), to define the places to count the number of "x"s tied to Item xxxxx. However, I fail to understand the rng and rows in the Offset section.

Tried several possibilities but some returned a 0 and others VALUE Error.

I will appreciate your help,

Chuck
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Sounds like there should be a column of the different codes and next to it a count if statement. Unless I'm missing something.

Col E Col F
A =countif(Col B, [cell to left])
B =countif(Col B, [cell to left])
C =countif(Col B, [cell to left])
D =countif(Col B, [cell to left])
.
.
.
 
Last edited:
Upvote 0
Maybe something like this. Copy formula down and across as needed.
Excel Workbook
ABCDEFGHIJ
1Prod. IDReturn CodeID / ReturnABCDEF
2ID100DID100100201
3ID106FID106001012
4ID102AID102100000
5ID100AID104010000
6ID104BID105001000
7ID105CID107001000
8ID106CID112101000
9ID107CID111100000
10ID100DID114000010
11ID106EID116000010
12ID112CID118002000
13ID111AID119010000
14ID112A
15ID106F
16ID114E
17ID100F
18ID116E
19ID118C
20ID118C
21ID119B
Sheet
 
Upvote 0
Maybe something like this. Copy formula down and across as needed.

AhoyNC... That is sweeeeet!. Rather than looking for a formula to calculate each condition, multi-copying your suggested formula yields a kinda of a live set! Actually I can extend the copying to additional rows, so that when new merchandise is added it is already set for returns computation. Obviously we would love no returns but...
Thanks again!
Chuck
 
Upvote 0
One thing to keep in mind when using SUMPRODUCT is that both ranges have to be at least roughly congruent. That is, if the first range is A1:A100, then the second range also has to have 100 rows. It cannot have more or fewer rows.
 
Upvote 0
One thing to keep in mind when using SUMPRODUCT is that both ranges have to be at least roughly congruent. That is, if the first range is A1:A100, then the second range also has to have 100 rows. It cannot have more or fewer rows.

Thanks BH... I adopted AhoyNC's solution but your point is well taken, in case of a future use of SUMPRODUCT. I have used that powerful function before but never with multiple criteria. Your observation comes handy for the latter.
Chuck
 
Upvote 0
You're welcome. Thanks for the feedback.
You could use SUMPRODUCT in the example above. So formula in E2 would be:

Code:
[TABLE="width: 382"]
<colgroup><col width="382"></colgroup><tbody>[TR]
   [TD="width: 382"]SUMPRODUCT(($A$2:$A$21=$D2)*($B$2:$B$21=E$1))[/TD]
 [/TR]
</tbody>[/TABLE]
Copy down and across.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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