CountIf with And

M

Mike

Novice Excel user on Excel 2003. I have a yearly data input sheet to track
codes. I use the date (fomatted as 1/01/2009) and a code. I want to track
the codes in a mothly chart for ease in summarization and improvment
tracking. The codes are used to define a department and an error in that
department (code 1a means - AR department and error a). I need to pull and
total the amount for each code for each month. After searching for a while
it seems that using CountIf with And does not work. Any suggestions would be
greatly appreciated.
 
M

Mike

Thanks Bob. The formula I used was =SUMPRODUCT(--(MONTH('Data
Entry'!B2:B65536)=4),--('Data Entry'!C2:C65536="1a"),'Data Entry'!J2:J15377)

I'm not sure what you meant by amount range. I added column J to give a
value of 1 for every entry and used that for the amount range. My dates are
in B and my codes are in C. The result I got was #VALUE!. I'm sure this is
a result of my inexperience but not sure what I have done wrong. Can you
tell from my formula?
 
B

Bernd P

Hello Mike,

Bob gave you a generic answer.

If its just counting you want and if your dates are in col B and your
codes are in col C then
=SUMPRODUCT(--(MONTH(B1:B365)=4),--(C1:C365="1A"))
for example, might give you what you need. Please note that the length
of your ranges needs to be identical.

But: If you select an area of let's say 30 rows and exactly 2 columns
and you array-enter
=Pfreq(C1:C365,MONTH(B1:B365))
you get your statistic for all appearing codes and all months
automatically.

This might save some manual effort and operational risk in case codes
are changing...

Regards,
Bernd
 
M

Mike

Thanks so much Bernd. One small issue though. My formula looks like this -
=SUMPRODUCT(--(MONTH('Data Entry'!$B$2:$B$365)=3),--('Data
Entry'!$C$2:$C$365="1A")). It does work, but is only tracking down to B and
C 365. I need this to track all the way to the bottom of the sheet if
needed. When I change the range to allow this it gives me #VALUE! as the
result. I think I need to use this style formula as the next row down will
be checking for error code 1B. Multiple errors can be recorded each day for
one code.
 
M

Mike

Again, thank you Bernd. I am VERY inexperienced with VBA and don't know how
to do anything. I opened the new module but had no idea what to do with it.
The error ocurrs in both B & C when I increase them or decrease from 365
individually but I tried them together and it worked fine. Can you recommend
a good website for beginners like me to learn some about VBA? Thank you for
your patience and assistance.
 
B

Bob Phillips

Bernd P said:
SUMPRODUCT is highly overrated, I think:
http://www.sulprobil.com/html/sumproduct.html


Maybe, but your thesis is poorly argued. You say

But there are limits to its usage: If you need to count all different
strings in a column and to list them together with their number of
occurrences, for example, you have to manually write down all different
entries and you have to maintain this list manually.

What is wrong with a simple extracted list using formulae? You use a highly
biased example to push your view without any mitigation.
 
B

Bernd P

Hello Bob,

Right, I pushed my view without mentioning formulae to extract unique
values because SUMPRODUCT is mostly being offered without doing so
(did you do so here?).

But you have a point here. I am thinking about showing four approaches
now:
1. Fomula extraction and SUMPRODUCT for *very* small lists.
2. My UDF's Pfreq and Sfreq for a wider range of lists (if a user is
able and willing to use VBA).
3. Pivot tables for more complex lists/statistics.
4. Database approach for problems of greater range / complexity.

I would be glad if you could turn your "Maybe" into an explicite
opinion: yes, no, or perhaps (when?)...

Regards,
Bernd
 
B

Bob Phillips

Bernd P said:
Hello Bob,

Right, I pushed my view without mentioning formulae to extract unique
values because SUMPRODUCT is mostly being offered without doing so
(did you do so here?).

Of course I did, because the OP asked for the solution and gave no mention
to the fact that he needed to extract the unique values to tabulate the
results. If he had I would have covered that aspect as well, but as he
didn't ...
But you have a point here. I am thinking about showing four approaches
now:
1. Fomula extraction and SUMPRODUCT for *very* small lists.


My answer to that is that it depends. Lots of SPs on large tables will be
slow, and it is better that users are aware of this. However, the VAST
majority of users I would contend use SP in very limited scenarios, and it
is not an issue. They not to solve a problem and SP Most often does this
very necessarily.

2. My UDF's Pfreq and Sfreq for a wider range of lists (if a user is
able and willing to use VBA).


Exactly, if they are able and willing. Many organisations preclude the use
of same, many users are scared by it - goodness knows why, but that is life.

3. Pivot tables for more complex lists/statistics.


I agree, but often the source data needs priming for pivots. Pivots are very
good, they are not great.

4. Database approach for problems of greater range / complexity.


Again I agree, especially when combined with pivots, but I am professional
developer. This would scare the bejeebers out of most of the posters here
who are offered SP solutions.

I would be glad if you could turn your "Maybe" into an explicite
opinion: yes, no, or perhaps (when?)...


No, it is a maybe and always will be in my view.

SP is extraordinarily versatile (actually, it is nothing to do with SP, it
is the ability to construct multiple condition tests, they could all be just
as easily deployed in array entered formulae), and provides an excellent
solution for 99.99% of the times in which they are offered (obviously that
is my conjecture, not a fact).

But, anyone who is going to use any array formula, and SP is just an array
formula it is just not array entered, should be aware of the difficulties
that can arise, and they should be aware of the potential solutions (helper
columns, VBA, etc.).

I would hope that anyone who does get an SP solution and then encounters
problems would either do some research into the issue, or ask some more and
learn the tings that we know implicitly (isn't it amazing how much hard work
and experience goes into implicit knowledge <g>), and develop their skills
accordingly. But I would be willing to bet these would be few and far
between.

I know array formulae can give rise to problems when used in the wrong
situations, but what can't (hundreds of pivots all with separate caches,
badly designed databases, linked workbooks, shared workbooks, ... I could go
on).

I think it is disingenuous to make the sort of sweeping statements that you
did. In fact, on writing this, I have changed my view, it is not a maybe, it
is a definite no. SUMPRODUCT, or in actuality the usage in the way that
SUMPRODUCT has evolved, is a very useful function.

To finish, I also disagree strongly with a statement you made in your SP
Pros. You said, ... You do not need Excel's © worksheet functions COUNTIF or
SUMIF. Actually, you should not (never!) even use them because you might
need to increase the number of conditions - and they only support ONE
(condition) ... This is very bad advice in my view, users should be aware of
as many tools at their disposal as possible, and use the correct one (I
prefer to use a screwdriver with screws rather than a hammer). Failure to do
so inevitable leads to abuse of the few tools that they do know, giving rise
to exactly the sort of problems that you hang on SUMPRDUCT.
 
B

Bernd P

Hello Bob,

Thanks for your frank and detailed answer.

We do not agree in some points.

My conclusion is that I might need to provide some more detailed
examples to convince more users of SUMPRODUCT's limits and of its time-
wasting tendency.

Regards
Bernd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top