How to count data based on lookup from 2 tables

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
333
Office Version
  1. 2010
Platform
  1. Windows
I have two lookup tables ID (Col A-C) and TYPE (Col E-I). I have colour coded them to help work out the combinations.
The DATA table (Col K-L) is what I need to count up based on each ID and TYPE combination, and the results to go under the total column in O. I have manually added the correct totals in column P
I'm not sure what formula to even start using to get the required totals. Any help is most appreciated.

I tried using COUNTIFS which works on it's own i.e. using either ID or TYPE, but fails when I try add both the ID and TYPE.

Staff Roles.xlsx
ABCDEFGHIJKLMNOP
1ID1ID2ID3TYPE1TYPE2TYPE3TYPE4TYPE5DATACOUNT DATATOTALS
2ROL001ROL006ROL011COT005COT007COT001COT103COT010IDTYPEID1 & TYPE11
3ROL002ROL016ROL012COT012COT008COT002COT116COT021ROL015COT117ID1 & TYPE21
4ROL003ROL019ROL013COT013COT014COT003COT117COT035ROL023COT015ID1 & TYPE31
5ROL004ROL020ROL014COT015COT022COT004COT115ROL032COT039ID1 & TYPE4
6ROL005ROL021ROL015COT016COT023COT006ROL002COT009ID1 & TYPE5
7ROL007ROL022ROL017COT017COT033COT009ROL001COT023
8ROL008ROL023ROL018COT019COT038COT011ROL023COT009ID2 & TYPE11
9ROL009ROL024ROL026COT025COT039COT018ROL006COT009ID2 & TYPE21
10ROL010ROL025ROL027COT026COT040COT020ROL023COT116ID2 & TYPE33
11ROL047ROL032ROL028COT029COT041COT024ROL023COT011ID2 & TYPE41
12ROL050ROL035ROL029COT102COT042COT027ROL002COT019ID2 & TYPE51
13ROL023COT021
14ID3 & TYPE1
15ID3 & TYPE2
16ID3 & TYPE3
17ID3 & TYPE41
18ID3 & TYPE5
Sheet2
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
With the following solution, you'll notice that I have split Column N into two columns so that it's easier to specify the criteria in the formula. Then, simply enter the formula in P2, confirm with CONTROL+SHIFT+ENTER, and copy down.

bradley.xlsm
ABCDEFGHIJKLMNOP
1ID1ID2ID3TYPE1TYPE2TYPE3TYPE4TYPE5DATACOUNT DATATOTALS
2ROL001ROL006ROL011COT005COT007COT001COT103COT010IDTYPEID1TYPE11
3ROL002ROL016ROL012COT012COT008COT002COT116COT021ROL015COT117ID1TYPE21
4ROL003ROL019ROL013COT013COT014COT003COT117COT035ROL023COT015ID1TYPE31
5ROL004ROL020ROL014COT015COT022COT004COT115ROL032COT039ID1TYPE40
6ROL005ROL021ROL015COT016COT023COT006ROL002COT009ID1TYPE50
7ROL007ROL022ROL017COT017COT033COT009ROL001COT023 
8ROL008ROL023ROL018COT019COT038COT011ROL023COT009ID2TYPE11
9ROL009ROL024ROL026COT025COT039COT018ROL006COT009ID2TYPE21
10ROL010ROL025ROL027COT026COT040COT020ROL023COT116ID2TYPE33
11ROL047ROL032ROL028COT029COT041COT024ROL023COT011ID2TYPE41
12ROL050ROL035ROL029COT102COT042COT027ROL002COT019ID2TYPE51
13ROL023COT021 
14ID3TYPE10
15ID3TYPE20
16ID3TYPE30
17ID3TYPE41
18ID3TYPE50
Sheet1
Cell Formulas
RangeFormula
P2:P18P2=IF(AND(LEN(N2)>0,LEN(O2)>0),SUM(IF(ISNUMBER(MATCH($K$3:$K$13,INDEX($A$2:$C$12,0,MATCH(N2,$A$1:$C$1,0)),0)),IF(ISNUMBER(MATCH($L$3:$L$13,INDEX($E$2:$I$12,0,MATCH(O2,$E$1:$I$1,0)),0)),1))),"")


Hope this helps!
 
Upvote 0
Solution
Thank you for this I would never have worked that one out. No wonder I was struggling.
I wasn't expecting you to use the text I put in column N. I only entered it like this to make it easier to understand. In the main project it's a completely different description. However, I will see if I can use it and just hide these reference columns. Thank you for you help with this.
 
Upvote 0
Thank you for this I would never have worked that one out. No wonder I was struggling.
You're very welcome, glad I could help.
I wasn't expecting you to use the text I put in column N. I only entered it like this to make it easier to understand. In the main project it's a completely different description. However, I will see if I can use it and just hide these reference columns. Thank you for you help with this.
Hiding the columns is one option, but it would seem to me that leaving them unhidden would make things a lot clearer. :)
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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