COUNTDIFF & IF Criteria

Reef

New Member
Joined
Jul 12, 2003
Messages
41
Hey Board,

I've been playing with the COUNTDIFF function (Morefunc) and find it great.

Now trying to nest an IF statement into the formula but having some trouble.

Hope someone could spare me some time to help with this? :)

Reef.

Data:
Column B contains Product Codes
Column C contains Y or N ... referring to yes or no.... whether the product has been selected
Column E refers to whether Copper is in the formula...it's on a few rows & blanks in the others

Formula: {=COUNTDIFF($E$2:$E$28,FALSE)}
Result: =1 .....shows that Copper is in the column.... Good.

Problem:
I need to countdiff only the rows in E2 to E28 that have a "Y" in C2 to C28.

I've tried {=COUNTDIFF(IF(C2:C28="Y",E2:E28),FALSE)} but it results in "2" if the two entries for copper have a "Y" next to them.

The aim is for the output to be....
"1" if any product with Copper in it is selected (with a "Y" in column B)
& "0" if I change the "Y"s to "N"s in column B.

Man... any ideas guys?? :)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Your question is not very clear; it may help if you post a clear concise example.

A guess follows

=IF(SUMPRODUCT(--(C2:C28="Y"),--(E2:E28="Copper"))>=1,1,0)
 
Upvote 0
Hi Dave,

Sorry.. just got html maker setup - slightly modified my sheet to simplify the post. :)

Your formula works but in the interest of my learning do you know what is wrong with my countdiff formula?....

Thank you massively fo your time :)

Reef
12.xls
ABCDEF
1BulkProductPicked(Y/N)Required-Copper
2Product-1Y
3Product-2Y
4Product-3YCopper
5Product-4Y
6Product-5Y
7Product-6Y
8Product-7YCopper
9Product-8Y
10Product-9Y
11Product-10Y
12Product-11Y
13Product-12Y
14Product-13Y
15Product-14Y
16Product-15Y
17Product-20Y
18Product-21Y
19Product-22Y
20Product-23Y
21Product-24Y
22Product-25Y
23Product-26Y
24Product-27Y
25CountTotal2
26Required(1/0)1
27MethodsCopper
28FormulaTesting2
29DavePatton'sFormula1
Sheet1
 
Upvote 0
CountDiff is invoked in order to obtain a distinct count, either (multi)-conditional or un-conditional. What is your objective?
 
Upvote 0
Hi Aladin Akyurek,

My aim is two fold....

1. The next step is to deal with more metals than just copper in column E. Hence the Countdiff.

2. To use Y or N values in column C to "what if" the products picked. As the products picked changes we can see what test methods will be needed.

Hope you can help :)

Many Thanks :)

Reef
 
Upvote 0
Hi Aladin Akyurek,

My aim is two fold....

1. The next step is to deal with more metals than just copper in column E. Hence the Countdiff.

2. To use Y or N values in column C to "what if" the products picked. As the products picked changes we can see what test methods will be needed.

Hope you can help :)

Many Thanks :)

Reef

The question is: Are you interested in distinct count or not?

Did you do a search on COUNTDIFF on this site? A few posts would certainly show up...
 
Upvote 0
Aladin Akyurek

I done a lot of reading of the board... this is where I found the Countdiff function in the first place.

My original post was asking about combining the countdiff function with the if function.

The logic looks right from the reading I have done on the board but for some reason it doesn't seem to be working.

Do you see any mistakes I have made in this formula?

{=COUNTDIFF(IF(C2:C28="Y",E2:E28),FALSE)}

Thanks for your time.

Reef
 
Upvote 0
a) Did you read the Help and Syntax provided with COUNTDIFF?

Counts the number of unique values in a range or an array.

SYNTAX : =COUNTDIFF(Array,Blanks,Exclude) Your formula doesn't follow the defined Syntax.


b) The Array formula {=SUM(IF($C$2:$C$24="Y",IF(E$2:E$24=E$27,1,0)))}
and the SumProduct yield the same answer. The formula
=IF(SUMPRODUCT(--(C2:C28="Y"),--(E2:E28="Copper"))>=1,1,0) includes the "IF" part because you stated "The aim is for the output to be....
"1" if any product with Copper in it is selected (with a "Y" in column B) "
 
Upvote 0
Hey Dave,

Yeah.. read the support info. I'm obviously missing something in trying to embed the IF into the COUNTDIFF.

I like your SUMPRODUCT idea. Think it will be fine if I don't try to include more than one type of metal test in any one column.

Will run with your SUMPRODUCT but hopefully can get my head around combining the COUNTDIFF & IF statements for future use.

Thanks for your help Dave.

Reef
 
Upvote 0
=COUNTDIFF(IF(C2:C28="Y",E2:E28),FALSE,FALSE)
Gives number of Unique with "Picked" = "Y"
a) Copper and Alum = 2
b) Copper and blanks evaluates to Copper and 0 =2

You could consider a Pivot Table; an actual Pivot Table looks
much better than the following


Count of Required Required
Picked Alum Copper Zinc Grand Total
N 1 19 20
Y 4 2 6
Grand Total 5 2 19 26
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,473
Members
448,967
Latest member
visheshkotha

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