count unique values in large range while excluding previous results

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
528
Office Version
  1. 365
Platform
  1. Windows
hi!
i want to count unique values from range of four cells, which sometimes will include duplicates, c2:f2
against a range of 8 cells, c3:f4,
for the example below, in c2:f2 there's two 2's, one 3, one 4,
in c3:f4 there's two 2's, three 3's, two 4's,
the wanted result is 4


uniques.xlsb
CDEFGHIJK
11234f1f2wanted result
22234304
32324303
43134303
52174
62582
test
Cell Formulas
RangeFormula
H2:H4H2=CountUnique($C$2:$F$2,C3:F4)
I2:I4I2=SUM(IF(FREQUENCY(IFERROR(MATCH(C2:F2,C3:F4,0),""),COLUMN(C2:F2)-COLUMN(C2)+1)>0,1))


tried the udf countunique, the original, and it doesn't work with two ranges if the second one is consist of two rows,

tried a modified one, and thought it worked, until tested with 4 values and still return only 3

tried:
=SUM(IF(FREQUENCY(IFERROR(MATCH(C2:F2,C3:F4,0),""),COLUMN(C2:F2)-COLUMN(C2)+1)>0,1))
but it doesn't work with range of two rows

nothing seems to work
any help?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I think we are going to need a clearer explanation of how you're getting your results.

How do you get 4 from the example that you described?

How do you get 3 from the other rows? Trying to figure out what you actually want, I think that the last one should be 2 instead of 3.
 
Upvote 0
i will try,
i want to count how many repeats of c2:f2 = 2-2-3-4 is there in c3:f4,
meaning count how many 2's there is in c3:f4 and if there's more then 2 exclude the rest,
and same for how many 3's and 4's

I think that the last one should be 2 instead of 3
you refers to k4? there's 3 because in c5:f5 = 2-1-7-4 ---> one 2 and one 4
and in c6:f6 there's 2-5-8-2 ----> two 2's
therefore 3 out of c2:f2 = 2-2-3-4
 
Upvote 0
I can see what you're asking for now, I'm going to see if I can do anything with native excel functions before putting it into a UDF.
 
Upvote 0
This looks like it works as needed but I've not tested beyond the sample that you provided.

data bar formatting.xlsm
CDEFGHIJ
11234f1wanted result
2223444
3232433
4313433
52174
62582
Sheet3
Cell Formulas
RangeFormula
H2:H4H2=LET(c,COUNT($C$2:$F$2),arr,INDEX(FREQUENCY(IFERROR(MATCH(C3:F4,$C$2:$F$2,0),c+1),SEQUENCE(c+1)),SEQUENCE(c)),ref,TRANSPOSE(COUNTIF($C$2:$F$2,$C$2:$F$2)),SUM(IF(arr<ref,arr,ref)))
 
Upvote 0
Solution
I'm wondering if it could be this? I have assumed all 1-digit numbers like the samples.

excelNewbie22.xlsm
CDEFG
11234Result
222344
323243
431342
52174
62582
Sheet3
Cell Formulas
RangeFormula
G2:G4G2=8-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(CONCAT(C3:F4),C2,"",1),D2,"",1),E2,"",1),F2,"",1))
 
Upvote 0
Trust me to over complicate things :oops:

Although, the mention of a "large range" in the thread title does have me wondering how close the sample is to the actual problem.
 
Upvote 0
Trust me to over complicate things :oops:
I don't know for sure what the actual requirement is but I thought that our two suggestions actually do different things.

Mine compares
C2:F2 with C3:F4, then
C3:F3 with C4:F5, then
C4:F4 with C5:F6
I was swayed this way by ..
I think that the last one should be 2 instead of 3


Doesn't yours compare the following?
C2:F2 with C3:F4, then
C2:F2 with C4:F5, then
C2:F2 with C5:F6
 
Upvote 0
The line that you quoted from the OP is actually them quoting my reply above, Peter. In post 1 the UDF had absolute references for C2:F2 while the FREQUENCY formula had relative references.
I started off using relative (which is why I thought that the last one should have been 2) but then looked at it again using absolute and found that I had the same results as the OP so went with that.

I think that both formulas will actually do the same thing if the data is consistent with the example, depending on whether absolute or relative refs are used.

Naturally, I'm expecting that both will require some adjustments when the OP tries them with their actual data.
 
Upvote 0
jason thank you very much!
peter, much appreciated too!
both your solutions works!
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,096
Members
452,542
Latest member
Bricklin

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