Complicated COUNTIF

megera716

Board Regular
Joined
Jan 3, 2013
Messages
150
Office Version
  1. 365
Platform
  1. Windows
Complicated for me anyway 🥲

I have a range with ~18,000 rows called Clients and another range with 200 rows called Names where I'm trying to calculate.

I put a COUNTIFS in Column C that counts the records that contain Name A, B or C AND Location 1.
C3:
Excel Formula:
=COUNTIFS(Clients!$C$3:$C$18261,$A3,Clients!$A$3:$A$18261,$B3)

There are 143 clients for Location 1, and the three people assigned to this location account for 124 of them. The other 19 are assigned to one of several names but I don't care about those.

Basically, what formula can I put in the Names range to count all the records in Clients that have any name that is assigned to Location 1 in the Names range (there might be just 3 as in my over-simplified example or there might be 37)? I will be working with the same 40ish locations every month but the Names assigned to a Location can and do change month to month so it has to be based on what is in Names.
1741210041570.png


1741210057659.png
 
With Power query

Power Query:
let
    Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Grouped Rows" = Table.Group(Source2, {"Location", "Name"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Grouped Rows",{"Name", "Location", "Count"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Name", Order.Ascending}, {"Location", Order.Ascending}})
in
    #"Sorted Rows"

Book7
ABCDEFGHIJ
1Table1Table2Result
2NamesAssigned to LocationLocationClientNameNameLocationCount
3A11Client11EA11
4B11Client35BA31
5C11Client36BB12
6D21Client83CC11
7E31Client15AC21
82Client86CD21
92Client10DE11
103Client29A
11
Sheet1
 
Upvote 0
Or with a formula:

Book2
ABCDEFGHIJ
1Table1Table2Result
2NamesAssigned to LocationLocationClientNameNameLocationCount
3A11Client11EA11
4B11Client35BA31
5C11Client36BB12
6D21Client83CC11
7E31Client15AC21
82Client86CD21
92Client10DE11
103Client29A
11
Sheet1
Cell Formulas
RangeFormula
H3:J9H3=LET(names,A3:A10,tbl,D3:F20,loc,INDEX(tbl,0,1),name,INDEX(tbl,0,3),f,FILTER(tbl,(name<>"")*COUNTIF(names,name)),u,SORT(UNIQUE(CHOOSECOLS(f,3,1))),c,COUNTIFS(name,INDEX(u,0,1),loc,INDEX(u,0,2)),HSTACK(u,c))
Dynamic array formulas.
 
Upvote 0
or maybe something like this:

Let Function - Map^J byRow^J Reduce^J Sum ^0 Count ^0 SumProduct solution for same problem - coersed array conditions.xlsx
BABBBC
8NamesLocation# of Clients
9A14
10B14
11C14
12D21
13E31
14F14
15
16
17
18
19
20
21
22
23
24LocationClientName
251Client11E
261Client35B
271Client46B
281Client23C
291Client49A
302Client12C
313Client90D
Sheet1
Cell Formulas
RangeFormula
BC9:BC14BC9=LET( d, UNIQUE(FILTER($BC$25:$BC$31,($BA$25:$BA$31=BB9))), c,COUNTA(d), c )
 
Upvote 0

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