How to include a CountIf that is column dependent?

helpneeded2

Board Regular
Joined
Jun 25, 2021
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I am not sure how to go forward on this sheet. (I am using Excel 365).

1. I have several columns of locations, lets call them: Store 1, Store 2, and Store 3.
2. Each column has several items, lets just call them: Fruit, Vegs, Meat.

On a different sheet, have a column that contains each of the Store names:

Column A;
Store 1
Store 2
Store 3

Now Column B will contain the total of all Fruits and Vegs (not Meat) for each location.

I'm not sure how combine the conditional countif (Fruit or Vegs) with what I am assuming would be a lookup or index?

Any guidance would be appreciated.

Thank you.
 

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.
The problem is, the countifs, still has to know where to go looking for the correct Store data.

In example:

On my results table, B2 should reference that since Store 1 will be column 1 of the lookup table/index, and then do the countifs.
 
Upvote 0
Please try this.

Book7
ABC
1Store 1Store 2Store 3
2FruitVegsMeat
3VegsVegsMeat
4MeatVegsMeat
5FruitVegsMeat
6FruitVegsMeat
7FruitVegsMeat
8FruitVegsMeat
9FruitVegsMeat
10VegsVegsMeat
11VegsFruitMeat
12MeatFruitMeat
13MeatFruitMeat
14MeatFruitMeat
Sheet1


Book7
ABCD
1Store NameFruitVegsMeat
2Store 1634
3Store 2490
4Store 30013
Sheet2
Cell Formulas
RangeFormula
A2:A4A2=TRANSPOSE(UNIQUE(Sheet1!A1:C1))
B2:D4B2=COUNTIF(OFFSET(Sheet1!$A$1,1,MATCH(Sheet2!$A2,Sheet1!$A$1:$R$1,0)-1,1000,1),Sheet2!B$1)
Dynamic array formulas.
 
Upvote 0
You should strongly consider setting up your data into a database style format. It is easier to quantify.
Book7
GH
1Store NameProduct
2Store 1Fruit
3Store 1Vegs
4Store 1Meat
5Store 1Fruit
6Store 1Fruit
7Store 1Fruit
8Store 1Fruit
9Store 1Fruit
10Store 1Vegs
11Store 1Vegs
12Store 1Meat
13Store 1Meat
14Store 1Meat
15Store 2Vegs
16Store 2Vegs
17Store 2Vegs
18Store 2Vegs
19Store 2Vegs
20Store 2Vegs
21Store 2Vegs
22Store 2Vegs
23Store 2Vegs
24Store 2Fruit
25Store 2Fruit
26Store 2Fruit
27Store 2Fruit
28Store 3Meat
29Store 3Meat
30Store 3Meat
31Store 3Meat
32Store 3Meat
33Store 3Meat
34Store 3Meat
35Store 3Meat
36Store 3Meat
37Store 3Meat
38Store 3Meat
39Store 3Meat
40Store 3Meat
Sheet1
 
Upvote 0
Thanks for your help, but I just can't get this to work the way I need it. Part of the problem is, that it is a very large spreadsheet which contains a lot of data, and I am trying to simplify it in my examples.

Here's the two conditions I am trying to capture in a single countifs:

=COUNTIF(INDEX('Raw Data'!$AP$2:$BR$12696,,MATCH($J2,'Raw Data'!$AP$1:$BR$1,0)),">"&0)
=COUNTIF('Raw Data'!AJ:AJ,"High") + COUNTIF('Raw Data'!AJ:AJ,"POI")

Here are the components:

Column J is my column of lookup header values from the columns AP to BR on "Raw Data". (It is not a formatted table, nor can it be which is why I am not using Headers).

For each row in J, I want to count the matches in the corresponding rows in the single matched column in AP to BR, however I only want it to do this if the value in column AJ on the related row is displaying either "High" or "POI".
 
Upvote 0
Please try this.
=TRANSPOSE(UNIQUE(Sheet1!A1:C1))[/XD][/XR][XR][XD]B2:D4[/XD][XD=fw:b]B2[/XD][XD]=COUNTIF(OFFSET(Sheet1!$A$1,1,MATCH(Sheet2!$A2,Sheet1!$A$1:$R$1,0)-1,1000,1),Sheet2!B$1)[/XD][/XR][/RANGE]

I finally figured out how to get this to work for my data. The OFFSET was key, and making sure it referenced the same number of max rows as my other countif references. Thanks for pointing me in the right direction.

(I also did not know of the TRANSPOSE function. I have been transposing through a complicated INDEX method. Thanks also for that.)
 
Upvote 0
If I read you right: You want a count of values above Zero and either have "High" or "POI" in column AJ. Please try this
Book2
JK
1Store Name
2Store 13
3Store 24
4Store 30
Sheet1
Cell Formulas
RangeFormula
K2:K4K2=LET(Rng,INDEX('Raw Data'!$AP$2:$BR$12696,,MATCH(Sheet1!$J2,'Raw Data'!$AP$1:$BR$1,0)),SUM((IFERROR(Rng*1,0)>0)*(('Raw Data'!$AJ$2:$AJ$12696="High")+('Raw Data'!$AJ$2:$AJ$12696="POI"))))
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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