Using Counta with Let function with filter

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,372
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've searched for the possible answer, but I'm stuck as to why I can't get the correct result, in column H. Column D/E are the expected results. I'm trying to count the unique values in column B by the unique in column A.

0247 Dynamic total row - Complete.xlsx
ABCDEFGH
1Hdr1Hdr2Hdr1Hdr2Hdr1Hdr2
2AppleCarApple2Apple1
3AppleCarOrange3Orange#N/A
4ApplePlane
5ApplePlane
6ApplePlane
7OrangeBus
8OrangeBus
9OrangeRocket
10OrangeRocket
11OrangeBoat
Sheet1
Cell Formulas
RangeFormula
G1:H3G1=LET(Header1,UNIQUE($A$2:$A$11),Header2,COUNTA(UNIQUE(FILTER($B$2:$B$11,$A$2:$A$11=Header1))),VSTACK(HSTACK("Hdr1","Hdr2"),HSTACK(Header1,Header2)))
D2:D3D2=UNIQUE(Sheet1!$A$2:$A$11)
E2:E3E2=COUNTA(UNIQUE(FILTER(Sheet1!$B$2:$B$11,Sheet1!$A$2:$A$11=D2)))
Dynamic array formulas.
 

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.
Are you only trying to count Apples and Oranges in A?
I ask, becasue I see you referenceing column B if it equals anything in column A; in this case Apple or Orange. However, I don't see Apple or Orange in column B, so I don't see it returning anything.
Also, you can drop the Sheet1! from the formula considering everything is on the same sheet (Sheet1).
 
Upvote 0
I'm trying to count the unique in column B that equals apple in column A. Then I count the unique in column B that equals orange in column A.
 
Upvote 0
A few options:
Book1
ABCDEFGH
1Hdr1Hdr2Hdr1Hdr2Hdr1Hdr2
2AppleCarApple2Apple2
3AppleCarOrange3Orange3
4ApplePlaneTotal5
5ApplePlane
6ApplePlane
7OrangeBus
8OrangeBus
9OrangeRocket
10OrangeRocket
11OrangeBoat
Sheet1
Cell Formulas
RangeFormula
D2:E4D2=GROUPBY(A2:A11,B2:B11,LAMBDA(x,COUNTA(UNIQUE(x))))
G2:H3G2=LET(u,UNIQUE(A2:A11),HSTACK(u,MAP(u,LAMBDA(m,SUM(--(TAKE(UNIQUE(A2:B11),,1)=m))))))
Dynamic array formulas.
 
Upvote 1
Solution
Thank you Cubist. I'll check these out when I get back to my spreadsheet, but pretty sure groupby is not and option within my version of Excel at work. Thanks again for your time.
 
Upvote 0
and you could perhaps use this to get a list of HDR2 for each HDR1, which is quite similar to D2 formula already suggested.

Book8
ABCDEFGH
1Hdr1Hdr2Hdr1Hdr2Hdr1Hdr2
2AppleCarApple2Apple2
3AppleCarOrange3Orange3
4ApplePlaneTotal5
5ApplePlane
6ApplePlaneAppleCar, Plane
7OrangeBusOrangeBus, Rocket, Boat
8OrangeBus
9OrangeRocket
10OrangeRocket
11OrangeBoat
Sheet1
Cell Formulas
RangeFormula
D2:E4D2=GROUPBY(A2:A11,B2:B11,LAMBDA(x,COUNTA(UNIQUE(x))))
G2:H3G2=LET(u,UNIQUE(A2:A11),HSTACK(u,MAP(u,LAMBDA(m,SUM(--(TAKE(UNIQUE(A2:B11),,1)=m))))))
G6:H7G6=DROP(GROUPBY(A2:A11,B2:B11,LAMBDA(a,ARRAYTOTEXT(UNIQUE(a)))),-1)
Dynamic array formulas.
 
Upvote 0
Hi @Cubist

I'm glad you jumped in, becasue for the life of me, I couldn't figure out how to get the CountA to spill with the UNIQUE values.

I think OP wants to include the Headers. So, I just recycled the V/HSTACK's before your GROUPBY code:
VBA Testing.xlsm
DE
1Hdr1Hdr2
2Apple2
3Orange3
4Total5
CountUnique
Cell Formulas
RangeFormula
D1:E4D1=VSTACK(HSTACK("Hdr1","Hdr2"), GROUPBY(A2:A11,B2:B11,LAMBDA(x,COUNTA(UNIQUE(x)))))
Dynamic array formulas.
 
Upvote 0
GROUPBY has a [field_headers] option.
Book1
ABCDE
1Hdr1Hdr2Hdr1Hdr2
2AppleCarApple2
3AppleCarOrange3
4ApplePlaneTotal5
5ApplePlane
6ApplePlane
7OrangeBus
8OrangeBus
9OrangeRocket
10OrangeRocket
11OrangeBoat
Sheet3
Cell Formulas
RangeFormula
D1:E4D1=GROUPBY(A1:A11,B1:B11,LAMBDA(x,COUNTA(UNIQUE(x))),3)
Dynamic array formulas.
 
Upvote 0
Thank you to all, and Cubist, I'll have to go with the Let version as I don't have GroupBy in my Excel version at work.
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,052
Members
453,522
Latest member
Seeker2025

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