473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to Count IF something AND something in Excel

48
Using Excel 2000, I need to count only if both of the criteria are met. Just for example, I have a list of fruits with price and dates beside it.

If I want to COUNT only when the price is more than $5 AND the date are blank.
[HTML]
Fruit Price Date
Apple $3 Jul-08
Kiwi $6 Jun-08
Orange $8
Apple $6 Jan-08
Kiwi $2 Jul-08
Apple $7
Kiwi $4

[/HTML] How to write the formula in excel so that I get "2" in the result column?
Jul 23 '08 #1
16 6372
RedSon
5,000 Expert 4TB
Did you read the help files for Excel on how to use the IF and AND in your formulas?
Jul 23 '08 #2
HowHow
48
I tried but I still don't get it. Can you please suggest formular to me please?
Jul 24 '08 #3
Brosert
57
You can construct the two conditions using AND
Expand|Select|Wrap|Line Numbers
  1. AND({condition1}, {condition2})
  2.  
Then you can use them as the condition in your COUNTIF statement....
Jul 24 '08 #4
HowHow
48
It still didn't work. Actually I try to test on IF function again and found even the single formular didn't work

Expand|Select|Wrap|Line Numbers
  1. =IF(C2="Jul-08",1,2)
Some of the dates in colume C are Jul-08, but the return values are all 2. Is that mean IF function cannot recognise date?
Jul 25 '08 #5
Brosert
57
Cells are specially formatted to show the date.
This means that while the cell displays Jul-08, it doesn't have that value (that is the display is an interpretation of the cells value, rather than the actual value).
Modify the Cell (using the Format->Cells) to be of type 'General' and see what value comes up (should be an largish integer).
You can compare with this integer value....
I thought you were looking for empty cells, though, so you could use

=IF(A1="",1,2)
Jul 25 '08 #6
HowHow
48
I changed the cell to general and it shows me 39630 instead of Jul-08, so I tested on it with the formula, =if(C2="39630",1,2) but it still gives me 2 instead of 1.

Actually I have another colume named "Negative" and some with number "1" in it. I need to calculate if the "Negative" colume has 1 and if it shows specific date.

I would imagine it is like =countif (D2:D200 = "1") AND (C2:C200 ="Jul-08). But now even test on the date it is not correct....
Jul 25 '08 #7
Brosert
57
Thast's the other trick I forgot to mention
39630 != "39630"
Excel wants a number not a string (in this instance).
Tri:
=if(c2=39630,1,2)
(With not Quotes)

The countif statement probably gives you an error.
You need the following format:
=Countif(Range, And({Cond1},{Cond2}))

it is also a little more complicated, because your criteria is outside the range you are counting...I'll ahve a think on that one....
Jul 25 '08 #8
Brosert
57
If you can afford another column, do the following:

in the toprow (I assuyme you have titles so I'll use 2)

=if(And(C2=69630, D2=1), 1, 0)

Fill down the length of that row.
Where you want the total do either
=Sum(E:E)
(Which you can do because we used 1)
OR
=COUNTIF(E:E,1)
Jul 25 '08 #9
HowHow
48
Now it drives me crazy, I kept trying and it keeps giving error message.
I think I am confused with the cond1 and cond2, whether I can put a range in it as well...etc etc...

By using the example (table above), Orange has 1 in Negative colume and Kiwi, date Jul-08 has 1 in negative colume too. if I need to count how many of them are negative in Jul-08, what formula you would suggest to be? (sorry, I try to copy and paste the table from Excel to here but it didn't work)
Jul 25 '08 #10
HowHow
48
I need to count the negative one for each month (of course because some of the negatives don't have a month), so if I add colume, it would mean adding 12 columes...is there a better way?
Jul 25 '08 #11
Brosert
57
Not sure I understand...
If you only have 1 -ve column, you only need 1 count column (ie E shows 1 if D is -ve AND the date is what you want.....
Expand|Select|Wrap|Line Numbers
  1.  
  2. A      B          C              D        E             F
  3. 1     Orange     Jul-08         $3       -7       =if(AND(C1=96930, E1<0),1,0)
  4.  
  5.  
  6. =count(F:F)
  7.  
  8.  
If you have multiple -ve columns already (one for each month), you can extract the Month from the Date and use that to create a column reference to the cell you want to access - which is more complicated but not impossible.
Jul 25 '08 #12
HowHow
48
I will just try to enter the data here so that you have a clearer idea of what I need:

[HTML]
Fruit Date Negative
Apple Jul-08
Kiwi Jul-08
Orange 1
Apple Jan-08
Kiwi Jul-08 1
Apple
Kiwi
Banana Aug-08 1
Grape Aug-08 1
[/HTML]

Using these info, I know that in Jul, I have 1 negative, in Aug I have 2 negative...at the end, I can provide a record of Jan-08, no negative, feb-08, no negative....Jul-08, 1 negative, Aug-08,2 negative...etc..something like that.
Jul 25 '08 #13
Brosert
57
That is a bit more complex....


I think (but haven't checked) You could use a nested if statement along the lines of

Expand|Select|Wrap|Line Numbers
  1. =sum(if(B1:b25=96930, if(C1:C25<>0,1,0),0)
  2.  
This works as follows:
count the return of "for each right date, for each negative return 1"....

of course, this will ignore whether your negative is 1,2,3,4....just whether it is there or not.....
Jul 25 '08 #14
HowHow
48
Thank You!!! yes, I can use nest, got it.
First I only add one colume with the formula:

Expand|Select|Wrap|Line Numbers
  1. =IF(AND(C2=39630,D2=1),7,"") & IF(AND(C2=39661,D2=1),8,"") & IF(AND(C2=39692,D2=1),9,"")
and so on, where 7 means July to me, 8 means Aug to me, 9 means September to me....etc for a financial year.

Then I have it in another colume with the month from Jul-08 to Jun-09, in colume next to it, I have this formula:

[HTML] Colume E Colume F
Jul-08 =countif(E2:E100,7)
Aug-08 =countif(E2:E100,8)
[/HTML]

And now I got the result that I needed! Thanks a lot!
Jul 25 '08 #15
Brosert
57
Truth be known, that wasn't quite what I meant....

But great to hear it's working!!!
Jul 25 '08 #16
RedSon
5,000 Expert 4TB
Truth be known, that wasn't quite what I meant....

But great to hear it's working!!!
There is more then one way to skin a cat!
Jul 25 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 ...
2
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell...
0
by: Ben Goodwin via .NET 247 | last post by:
Hi all. I am stuck on a COM Add-In problem in C#. The code is based onhttp://support.microsoft.com/kb/302901/EN-US/ What I want to do is make the "My Button" gather data from arange of cells. The...
1
by: javzxp | last post by:
Hi I'd like to use C# to open an existing Excel workbook and save each worksheet it contains into a new Excel file. The name of each new Excel file should be the name of the worksheet copied...
2
by: pengb | last post by:
Hello All: A pretty frustrating question to ask! I use the string something = stringx.split (delimiter.tochararray()) mathod to delimit a long string by space! So supposely if the stringx is :...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: rajeshkothuru | last post by:
Hi I am new to perl programming, i stcked at one line. I have written code such that new excel sheet will save accordingly even though if already existed Excel sheet persists. The problem is if...
3
by: jed | last post by:
What is the best way for me to send data from C# to excel and open the file in excel from a windows application please help.Is there an add on i can download to gain access to the excel namespace...
7
by: bobh | last post by:
Hi, I have this code in the groupheader_print section of an AccessXP report. What is the code to 'Bold' the text288 cell. thanks bobh. 'this is the rpting category header wks.Cells(row, 1) =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.