Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I have a spreadsheet with 350 rows and two columns.
I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
try
=sumproduct((G2:G350="C")*(B2:B350="Y")) -- Don Guillett SalesAid Software "Kaishain" wrote in message ... I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
This one works:
=SUMPRODUCT(--(G2:G350="C"),--(B2:B350="Y")) "Kaishain" wrote: I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() Thanks for replying! They both seem to work for me. What's the difference? Is either one better for one reason or another? Thanks again "Byron720" wrote: This one works: =SUMPRODUCT(--(G2:G350="C"),--(B2:B350="Y")) "Kaishain" wrote: I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
By and large there is no difference between the two methods. In a few cases, one will work better than the other. Sumproduct generally has its different terms separated by commas =Sumproduct(term1,term2,term3). In your case the terms are comparisons that will either result in a True or False result. These results need to be coerced from True to 1 and False to 0 in order for Sumproduct to be able to produce a result. The double unary minus -- is used to carry out the coercion. The same could be achieved by adding 0 to the result or multiplying by 1 =SUMPRODUCT((G2:G350="C")*1,(B2:B350="Y")*1) In the other case, the coercion is automatically taking place by using the multiplication of the 2 terms within the Sumproduct, rather than using a comma separator. For a full discussion on this, Bob Phillips has an excellent treatise at http://xldynamic.com/source/xld.SUMPRODUCT.html -- Regards Roger Govier "Kaishain" wrote in message ... Thanks for replying! They both seem to work for me. What's the difference? Is either one better for one reason or another? Thanks again "Byron720" wrote: This one works: =SUMPRODUCT(--(G2:G350="C"),--(B2:B350="Y")) "Kaishain" wrote: I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks again for the quick reply. It makes a lot more sense now.
However, I now have another problem: There is a third column which contains different numbers (currency, in this case). The formula used to count the rows returned 31 rows that met the specified conditions. I now want to add the values of the third column of each of those rows. I want something like '=SUM(C1:C350)', but only counting the 31 rows found by the first formula. Is it possible to do that? "Roger Govier" wrote: Hi By and large there is no difference between the two methods. In a few cases, one will work better than the other. Sumproduct generally has its different terms separated by commas =Sumproduct(term1,term2,term3). In your case the terms are comparisons that will either result in a True or False result. These results need to be coerced from True to 1 and False to 0 in order for Sumproduct to be able to produce a result. The double unary minus -- is used to carry out the coercion. The same could be achieved by adding 0 to the result or multiplying by 1 =SUMPRODUCT((G2:G350="C")*1,(B2:B350="Y")*1) In the other case, the coercion is automatically taking place by using the multiplication of the 2 terms within the Sumproduct, rather than using a comma separator. For a full discussion on this, Bob Phillips has an excellent treatise at http://xldynamic.com/source/xld.SUMPRODUCT.html -- Regards Roger Govier "Kaishain" wrote in message ... Thanks for replying! They both seem to work for me. What's the difference? Is either one better for one reason or another? Thanks again "Byron720" wrote: This one works: =SUMPRODUCT(--(G2:G350="C"),--(B2:B350="Y")) "Kaishain" wrote: I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
=SUMPRODUCT((G2:G350="C")*(B2:B350="Y")*(C2:C350)) Strictly speaking, as they are just numbers in column C, they don't need to be enclosed within another set of parentheses, but I usually find it easier to always enclose each term in this way. -- Regards Roger Govier "Kaishain" wrote in message ... Thanks again for the quick reply. It makes a lot more sense now. However, I now have another problem: There is a third column which contains different numbers (currency, in this case). The formula used to count the rows returned 31 rows that met the specified conditions. I now want to add the values of the third column of each of those rows. I want something like '=SUM(C1:C350)', but only counting the 31 rows found by the first formula. Is it possible to do that? "Roger Govier" wrote: Hi By and large there is no difference between the two methods. In a few cases, one will work better than the other. Sumproduct generally has its different terms separated by commas =Sumproduct(term1,term2,term3). In your case the terms are comparisons that will either result in a True or False result. These results need to be coerced from True to 1 and False to 0 in order for Sumproduct to be able to produce a result. The double unary minus -- is used to carry out the coercion. The same could be achieved by adding 0 to the result or multiplying by 1 =SUMPRODUCT((G2:G350="C")*1,(B2:B350="Y")*1) In the other case, the coercion is automatically taking place by using the multiplication of the 2 terms within the Sumproduct, rather than using a comma separator. For a full discussion on this, Bob Phillips has an excellent treatise at http://xldynamic.com/source/xld.SUMPRODUCT.html -- Regards Roger Govier "Kaishain" wrote in message ... Thanks for replying! They both seem to work for me. What's the difference? Is either one better for one reason or another? Thanks again "Byron720" wrote: This one works: =SUMPRODUCT(--(G2:G350="C"),--(B2:B350="Y")) "Kaishain" wrote: I have a spreadsheet with 350 rows and two columns. I want to count the number of rows which have BOTH the letter C in the first column AND the letter Y in the second column. I was thinking of using COUNTIF in a way similar to the following: '=COUNTIF(G2:G350,"C")+COUNTIF(B2:B350,"Y")' However, this counts the number of CELLS which contain EITHER of those two letters. I want to count the number of ROWS with BOTH of those letters. I'm guessing COUNTIF is the wrong command to use, but that I want something similar to it. Any suggestions would be much appreciated. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
COUNTIF with multiple conditions | Excel Discussion (Misc queries) | |||
Find and Count Frequency of Numeric Value in Non-Contiguous Rows | Excel Worksheet Functions | |||
Using CountIf with 2 conditions - help! | Excel Worksheet Functions | |||
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next | New Users to Excel | |||
Count on multiple values with duplicate rows | Excel Worksheet Functions |