Counting Unique Outcomes

cotech_10

Board Regular
Joined
Sep 11, 2010
Messages
135
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I using an Excel Function Formula where I am trying to achieve a particular outcome. The current Formula looks like this:

=SUMPRODUCT(--(COUNTIF(O3:Y3,$O$4:$Y$4)>0))


I have two sets of data as per Example 1 below:

1. Range Data
2. Criteria Data

Sumprod_1.JPG




What I am currently doing is counting the unique only appearances found
in the Range Data against the Criteria Data


So for example the count of those events from the above data would = 7
Broken down as follows:

Range Data 200 Count = 1 (even though it appears more than once in the
Range Data Table we are only counting its unique
appearance against the Criteria Table

Therefore for the other Data in the Range Data Table we have:

300 - appears once in Range Data Table but appears in the Criteria Data Table Count = 1
400 - appears once in Range Data Table but appears in the Criteria Data Table Count = 1
500 - appears once in Range Data Table but appears in the Criteria Data Table Count = 1
600 - appears once in Range Data Table but appears in the Criteria Data Table Count = 1
70 - appears once in Range Data Table but no appearance in the Criteria Data Table Count = 0
800 - appears once in Range Data Table but appears in the Criteria Data Table Count = 1
99 - appears twice in Range Data Table but appears in the Criteria Data Table Count = 1
111 - appears once in Range Data Table but no appearance in the Criteria Data Table Count = 0


This all works fine with Contiguous Criteria Data but what I would like to achieve is to
select non adjacent Criteria Data and perform the same Unqiue Count as above

For example as per the Image below:

In this example I have selected Criteria Values of "120","200", "500", "300", and "800" highlighted in Orange and
resulting in a Unique Count of "4"

Sumprod_2.JPG



I look forward in hearing from someone around this request




Regards
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you want to select the cells of interest, you will need a VBA solution, as a formulaic approach will not be able to recognize the selected cells. If you are interested in a formula-based approach, then you might consider using a table to specify which items in the main Criteria Data array should be included...as shown in the following where examples 1, 2, 3, and 4 use the numeral 1 to specify keeping the corresponding item from the main criteria array. Your original formula is slightly modified to construct the new criteria array. One concern with this approach is the two arrays are multiplied, so you will get 0's in the new array, and if 0 is ever a component of your main Range array, this will likely generate an incorrect count. A possible work-around is to consider using x's (or some other specifier) as shown in examples 3b and 4b. Here, your original formula is modified with an IF statement to generate the new criteria array, and blanks are introduced if the main criteria array item is not to be included.
MrExcel_20230523.xlsx
NOPQRSTUVWXYZ
3Range Data2003004005006007008009999111200
4Criteria Data12020015050040099999450600300800
5
6Unique Count7
7
8Range Data2003004005006007008009999111200
9Criteria Data12020015050040099999450600300800Unique Count
10Criteria Example 1111111111117
11Criteria Example 2111114
12Criteria Example 311112
13Criteria Example 411113
14Criteria Example 3bxxxx2
15Criteria Example 4bxxxx3
cotech_10
Cell Formulas
RangeFormula
O6O6=SUMPRODUCT(--(COUNTIF(O3:Y3,$O$4:$Y$4)>0))
Z10:Z13Z10=SUMPRODUCT(--(COUNTIF($O$8:$Y$8,($O$9:$Y$9)*($O10:$Y10))>0))
Z14:Z15Z14=SUMPRODUCT(--(COUNTIF($O$8:$Y$8,IF($O14:$Y14="x",$O$9:$Y$9,""))>0))
 
Upvote 0
Hi Kirk,

Thank you for your efforts and response.. You are correct in advising that this would be better suited with a VB solution,
but I will go forward with your solution as above and see how I go with it.

Once again thanks again for your efforts it is much appreciated.
 
Upvote 0
I'm happy to help. Please post back if you run into any difficulties.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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