Countif by cross-referencing different tables

mrblister

Board Regular
Joined
Nov 20, 2016
Messages
191
Office Version
  1. 2019
Platform
  1. Windows
Hi all! Would like help with the below please:

TABLE 1
ABC
2GoodsSalesmanUnits Sold
3FaxBrown
1​
4PhoneSmith
10​
5FaxJones
20​
6FaxSmith
30​
7PhoneJones
40​
8PCSmith
50​
9FaxBrown
60​
10PhoneDavis
70​
11PCJones
80​

TABLE 2

GHIJ
2RequirementsFaxPhonePC
3Internet
1​
1​
4Monitor
1​
5Power
1​
1​
6Landline
1​
1​

So I'm looking for formulas to:
  1. Count the Total sales (ie count the # of rows; NOT Units Sold), of goods requiring Power, by Jones. (The answer should be 2).
  2. Get Total Units Sold, of goods requiring Power, by Jones. (The answer should be 100).
Notes:
  • Formula 1 is more important of the two.
  • The above tables are an example; my real spreadsheet has A LOT of different types of "Product" and the "Requirements" list is even larger, so I can't use a simple formula (ie have a bunch of IF statements for each good type and Requirement). Because the real tables are so large, formula efficiency may or may not be a consideration, but I'll gladly take any answer!

Thanks in advance!
 
Secondly, it took me like 1 minute to solve this using Power Query. I'm wondering if you can use this too.
Cell FormulasRangeFormulaK3:N6K3=COUNT(FILTER($C$2:$C$10,($B$2:$B$10=K$2)*HLOOKUP($A$2:$A$10,$F$1:$H$5,MATCH($J3,$E$1:$E$5,0),0)))K10:N13K10=SUM(FILTER($C$2:$C$10,($B$2:$B$10=K$9)*HLOOKUP($A$2:$A$10,$F$1:$H$5,MATCH($J10,$E$1:$E$5,0),0),0))

Hello GraH and Peter_SSs, thank you for the replies. Sorry for the delay in my reply, I wasn't aware that I had received additional posts after my last post.

@GraH, thanks fo the introduction to Power Query.
@Peter_SSs, thanks for the formulas.

When I thought I didn't get any replies, I kept hammering at the problem, and came up with my own solution:

ABCDEFGH
1TABLE 1TABLE 2
2ProductSalesmanUnits SoldHelper 4RequirementsFaxPhonePC
3FaxBrown
1​
FaxInternetPowerLandlineInternet
1​
1​
4PhoneSmith
10​
PhoneLandlineMonitor
1​
5FaxJones
20​
FaxInternetPowerLandlinePower
1​
1​
6FaxSmith
30​
FaxInternetPowerLandlineLandline
1​
1​
7PhoneJones
40​
PhoneLandline
8PCSmith
50​
PCInternetMonitorPowerHelper 3FaxInternetPowerLandlinePhoneLandlinePCInternetMonitorPower
9FaxBrown
60​
FaxInternetPowerLandline
10PhoneDavis
70​
PhoneLandline
11PCJones
80​
PCInternetMonitorPower
12
13ANSWER MATRIX
14BrownSmithJonesDavis
15Internet
2​
2​
2​
0​
16Monitor
0​
1​
1​
0​
17Power
2​
2​
2​
0​
18Landline
2​
2​
2​
1​

With the assistance of Helper 3 Row and Helper 4 Column, formula in B15 is:
=COUNTIFS($D$3:$D$11,"*"&$A15&"*",$B$3:$B$11,B$14)

It works, and compared to my previous formula is fast because it's not an array formula.

Notes:
  • Still kinda slow. Maybe because Helper 3 and Helper 4 formulas are array formulas (Table 1 and Table 2 are quite large in real life, so simple nested-ifs would be too huge).
  • Wasn't crazy about Helper 4 column, because in real life that's on my source data sheet (so I was trying to keep formulas off of it) but it's not a big deal.
Again, thanks for the replies!
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
When I run the formula evaluation all is fine until this step = SUMPRODUCT({1;0;0;0;0;0;1;0;0};1)
That looks like a non-CSE formula evaluation. Do you get that in formula evaluation with CSE entry?
With CSE processing the penultimate step in the evaluation of cell K5 should be

1589766053397.png



Again, thanks for the replies!
You're welcome. Glad you are up-and-running. :)
 
Upvote 0
That looks like a non-CSE formula evaluation. Do you get that in formula evaluation with CSE entry?
With CSE processing the penultimate step in the evaluation of cell K5 should be

View attachment 14122
It doesn't do that on my end. I've been Running the formula evaluation like you did. That's puzzling...
Anyways, thanks for the additional feedback.
 
Upvote 0
With CSE processing the penultimate step in the evaluation of cell K5 should be
Just FYI Peter_SSs I tried your formula, and my results are also different from your own. In my penultimate step, it reads: SUMPRODUCT({1;0;0;0;0;0;1;0;0},--TRUE).

My last steps in the calculation are:
  1. SUMPRODUCT({1;0;0;0;0;0;1;0;0},(INDEX($F$3:$H$6,3,1)>0))*
  2. SUMPRODUCT({1;0;0;0;0;0;1;0;0},--(1>0))
  3. SUMPRODUCT({1;0;0;0;0;0;1;0;0},--(TRUE))
  4. SUMPRODUCT({1;0;0;0;0;0;1;0;0},--TRUE)
  5. #VALUE!
*- My table config is a little different from the example, but the rows and columns should be correct.
 
Upvote 0
Just FYI Peter_SSs I tried your formula, and my results are also different from your own. In my penultimate step, it reads: SUMPRODUCT({1;0;0;0;0;0;1;0;0},--TRUE)
Did you confirm the formula with Ctrl+Shift+Enter, not just Enter? To be sure, select one of the formula cells & press F2 then Ctrl+Shift+Enter.
If that fixes the problem then copy that cell to the other formula cells.
 
Upvote 0
Did you confirm the formula with Ctrl+Shift+Enter, not just Enter? To be sure, select one of the formula cells & press F2 then Ctrl+Shift+Enter.
If that fixes the problem then copy that cell to the other formula cells.
Yes. I entered formula as array (Ctrl+Shift+Enter).
 
Upvote 0

Forum statistics

Threads
1,215,088
Messages
6,123,056
Members
449,091
Latest member
ikke

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