Complex Counting - Count positive values in a table row with a 'Table Criteria'

Foxu666

New Member
Joined
Mar 15, 2017
Messages
1
Hi,

Would like to know if there's a single cell formula that would solve my Excel problem.

Would like to count (per row) how many values that is above 0 in table 2 using the criteria table (ex. add to count if Town and Juice = 1 in table 1 and positive value in Table 2)

The answer I wanted to generated can be seen in the Table, right of Table 2.

Here are sample tables.

Table 1 = Criteria Table
Criteria TableTownSlumsCity
Juice101
Milk001
Bread111
Chocolate101

<tbody>
</tbody>

Table 2 = Main Table

NameTypeJuiceMilkBread
New VegasTown1005
DiamondCity15310
WhiterunTown085

<tbody>
</tbody>
NameCount
New Vegas2
Diamond3
Whiterun1

<tbody>
</tbody>

Please note:
Table 1 is a static table.
Table 2 is pivot table meaning its dynamic therefore Columns and Rows of Table 2 may change when raw data is changed (columns may end up with a set of Milk, Bread, and Chocolate or all 4 present).

I've tried using Sumproduct and Countifs with Index Match but I cant seem to get the correct formula.

If there are other techniques other than a formula is ok, i haven't tried using pivot table using 2 data source yet.

Help is greatly appreciated.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the forum.

I hope I comprehended your objective.

I created an algorithm that uses helper columns just so I could get a handle on the complex lookup requirements. I then created a single-cell formula to meet your needs.

Note that I had to create the entire set of possible food items in the Main Table to make this work. I don't know how your PivotTable will affect all this, but I think maybe you can tell the PT to include zeroed items. In any event let's try this for now.

Copy C14 across and down to F16. Copy G14 and H14 down to row 16.

ABCDEFGH
1CriteriaTownSlumsCity
2Juice101
3Milk001
4Bread111
5Chocolate101
6
7NameTypeJuiceMilkBreadChocolate
8New VegasTown10050
9DiamondCity153100
10WhiterunTown0850
11
12
13NameJuiceMilkBreadChocolateCount (helpers)Count (single-cell)
14New VegasTown101022
15DiamondCity111033
16WhiterunTown001011

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet45

Worksheet Formulas
CellFormula
C14=IF(INDEX($B$2:$D$5,MATCH(C$7,$A$2:$A$5,0),MATCH(VLOOKUP($A14,$A$8:$B$10,2,0),$B$1:$D$1,0))*INDEX(C$8:C$10,MATCH($A14,$A$8:$A$10,0)),1,0)
G14=SUM(C14:E14)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
H14{=SUMPRODUCT((IF(INDEX($C$8:$F$10,MATCH(A14,$A$8:$A$10,0),N(IF(1,COLUMN($C$7:$F$7)-COLUMN($C$7)+1)))*TRANSPOSE($B$2:$D$5),1,0))*(VLOOKUP(A14,$A$8:$B$10,2,0)=TRANSPOSE($B$1:$D$1)))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try to enter the {} manually yourself.

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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