LEFT not working in a COUNTIF formula

TonyD1016

Board Regular
Joined
Nov 18, 2021
Messages
59
Office Version
  1. 365
Platform
  1. Windows
I have a column of data on a table that consists of 3-digit numbers.

I need to strip the third digit and count the unique instances of the remaining two digit numbers in the column.

So on another sheet in A1 I have the following:
Excel Formula:
=(LEFT(range,2)

And that spills an array of the results I need to count.
Then B and C I put the following:
Excel Formula:
=UNIQUE(A1#)
=COUNTIF(A1#,UNIQUE(A1#))
Which returns exactly the totals I need.

So I return to my first sheet and put in:
Excel Formula:
=UNIQUE(LEFT(range,2))
It works fine, but when I go to the adjacent column and try to type the following:
Excel Formula:
=COUNTIF((LEFT(range,2),UNIQUE(LEFT(range,2)))
...I get the Excel stop warning of "There's a problem with this formula."

What gives?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Don't know for sure what gives, but here's an alternative to try:
Excel Formula:
=COUNTA(UNIQUE(LEFT(range,2)))
 
Upvote 0
Don't know for sure what gives, but here's an alternative to try:
Excel Formula:
=COUNTA(UNIQUE(LEFT(range,2)))
That formula returns the total amount of unique two-digit numbers.
What I need is a count of the total instances of each two-digit number.
 
Upvote 0
What's wrong with using
Excel Formula:
=UNIQUE(A1#)
=COUNTIF(A1#,UNIQUE(A1#))
You cannot use
Excel Formula:
=COUNTIF((LEFT(range,2),UNIQUE(LEFT(range,2)))
as countif does not accept an array as the 1st argument.
 
Upvote 0
You can only use ranges, not arrays, for anything but the criteria in COUNTIF. LEFT(range, 2) returns an array, so won't work.
 
Upvote 0
If you don't want the helper column, how about
+Fluff 1.xlsm
ABCDEFG
1
217317174174
316616163163
411611113113
514714145145
619619196196
719919123123
819219184184
917117131131
1014914
1112012
1219819
1318718
1412012
1511011
1618118
1714214
1813913
1919619
2011711
2114214
2218018
2317617
2416516
2519719
2614014
2718218
2816016
2912112
3017717
31
Main
Cell Formulas
RangeFormula
B2:B30B2=LEFT(A2:A30,2)
C2:C9C2=UNIQUE(B2#)
D2:D9D2=COUNTIFS(B2#,C2#)
F2:G9F2=LET(Rng,A2:A30,l,LEFT(Rng,2),u,UNIQUE(l),CHOOSE({1,2},u,MMULT(--(TRANSPOSE(l)=u),SEQUENCE(ROWS(Rng),,,0))))
Dynamic array formulas.
 
Upvote 0
Or a simpler version
Excel Formula:
=LET(Rng,A2:A30,l,LEFT(Rng,2),u,UNIQUE(l),CHOOSE({1,2},u,COUNTIFS(Rng,">="&u*10,Rng,"<"&u*10+10)))
 
Upvote 0
Or a simpler version
Excel Formula:
=LET(Rng,A2:A30,l,LEFT(Rng,2),u,UNIQUE(l),CHOOSE({1,2},u,COUNTIFS(Rng,">="&u*10,Rng,"<"&u*10+10)))

I could use the helper column on a hidden sheet if that would be the simplest solution. I'm mostly curious at this point if I can do without it.

The problem I am running into with both of those formulas appears to be that some of the data I am working with has a leading zeros. It's all stored as text because I don't use it in any calculations. So for instance "081", "087", and "016", which I have to count as two "08"s and one "01" respectively.

The formula from your first post ignores these leading zero instances entirely in its results, and the second formula returns the leading zeroes in the list but returns all zeroes for the counts.
 
Upvote 0
If col A is all stored as text, then that's even simpler.
Excel Formula:
=LET(Rng,A2:A30,l,LEFT(Rng,2),u,UNIQUE(l),CHOOSE({1,2},u,COUNTIFS(Rng,u&"*")))
 
Upvote 0
Solution
If col A is all stored as text, then that's even simpler.
Excel Formula:
=LET(Rng,A2:A30,l,LEFT(Rng,2),u,UNIQUE(l),CHOOSE({1,2},u,COUNTIFS(Rng,u&"*")))
? That worked.
So concatenating a wildcard to the unique values is what I was missing? How does that work?
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,830
Members
449,096
Latest member
Erald

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