COUNTIF based on data in two columns

RodneyC

Active Member
Joined
Nov 4, 2021
Messages
278
Office Version
  1. 2016
Platform
  1. Windows
This may be hard to explain and hopefully the attached image will help.

I have about 66,000 lines of data on a tab named WO. I need to COUNTIF and SUMIFS on a tab named CAT.

Column C on the WO tab contains a list of names. I'm using colors in the example but across the 66,000 lines there are probably 17000 different names so the formula needs to include a cell reference not a name reference. In the example, you will see there are 13 lines with the value Green. If I was to do a simple COUNTIF, the result would be 13. However, Green is also connected to the values in column D. There are four different values associated with Green: Breakfast, Lunch, Dinner and Dessert.

I need a COUNTIF formula that will count the total as 4 not 13. This is important as another column is calculating averages and it needs to be based on 4, not 13.

Thank you in advance
WOave.xlsx
BCDEFGHIJKL
1Column D on CAT tabColumn E on CAT tabColumn F on CAT tab
2
3ColorMealCostCountSumAverage
4GreenBreakfast$12Green13$255$20
5GreenBreakfast$7Blue2$26$13
6GreenBreakfast$16Red1$264$264
7GreenBreakfast$8Orange2$51$26
8GreenLunch$14
9GreenLunch$18
10GreenLunch$21What I want
11GreenLunch$9Green4$255$64
12GreenLunch$37Blue2$26$13
13GreenLunch$25Red1$264$264
14GreenLunch$26Orange2$51$26
15GreenDinner$17
16GreenDessert$45
17BlueBreakfast$11
18BlueLunch$15
19RedDinner$65
20RedDinner$46
21RedDinner$76
22RedDinner$77
23OrangeBreakfast$12
24OrangeBreakfast$16
25OrangeLunch$23
26
WO
Cell Formulas
RangeFormula
I4I4=COUNTIF(C4:C25,H4)
J11:J14,J4:J7J4=SUMIFS($E$4:$E$25,$C$4:$C$25,H4)
K11:K14,K4:K7K4=J4/I4
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:

Book1
ABCDEFGHIJK
1Column D on CAT tabColumn E on CAT tabColumn F on CAT tab
2
3ColorMealCostCountSumAverage
4GreenBreakfast12Green1325519.61538
5GreenBreakfast7Blue22613
6GreenBreakfast16Red1264264
7GreenBreakfast8Orange25125.5
8GreenLunch14
9GreenLunch18
10GreenLunch21What I want
11GreenLunch9Green425563.75
12GreenLunch37Blue22613
13GreenLunch25Red1264264
14GreenLunch26Orange25125.5
15GreenDinner17
16GreenDessert45
17BlueBreakfast11
18BlueLunch15
19RedDinner65
20RedDinner46
21RedDinner76
22RedDinner77
23OrangeBreakfast12
24OrangeBreakfast16
25OrangeLunch23
Sheet3
Cell Formulas
RangeFormula
I4I4=COUNTIF(C4:C25,H4)
J4:J7,J11:J14J4=SUMIFS($E$4:$E$25,$C$4:$C$25,H4)
K4:K7,K11:K14K4=J4/I4
I11:I14I11=SUMPRODUCT(SIGN(FREQUENCY(IF(C$4:C$25=H11,MATCH(D$4:D$25,D$4:D$25,0)),ROW(D$4:D$25)-ROW(D$4)+1)))


You may need to enter the I11 formula with Control+Shift+Enter on your version of Excel. I'd also worry a bit about performance with 66K rows.
 
Upvote 0
Similar caveats with my offering.
Book1
CDEFGHIJK
1Column D on CAT tabColumn E on CAT tabColumn F on CAT tab
2
3ColorMealCostCountSumAverage
4GreenBreakfast12Green1325519.61538462
5GreenBreakfast7Blue22613
6GreenBreakfast16Red1264264
7GreenBreakfast8Orange25125.5
8GreenLunch14
9GreenLunch18
10GreenLunch21What I want
11GreenLunch9Green425563.75
12GreenLunch37Blue22613
13GreenLunch25Red1264264
14GreenLunch26Orange25125.5
15GreenDinner17
16GreenDessert45
17BlueBreakfast11
18BlueLunch15
19RedDinner65
20RedDinner46
21RedDinner76
22RedDinner77
23OrangeBreakfast12
24OrangeBreakfast16
25OrangeLunch23
WO
Cell Formulas
RangeFormula
I4I4=COUNTIF(C4:C25,H4)
J4:J7,J11:J14J4=SUMIFS($E$4:$E$25,$C$4:$C$25,H4)
K4:K7,K11:K14K4=J4/I4
I11:I14I11=SUMPRODUCT(IFERROR(($C$4:$C$25=$H4)/(COUNTIFS($C$4:$C$25,$H4,$D$4:$D$25,$D$4:$D$25)),""))
 
Upvote 0
@RodneyC Typically, are your names grouped, a

Try:

Book1
ABCDEFGHIJK
1Column D on CAT tabColumn E on CAT tabColumn F on CAT tab
2
3ColorMealCostCountSumAverage
4GreenBreakfast12Green1325519.61538
5GreenBreakfast7Blue22613
6GreenBreakfast16Red1264264
7GreenBreakfast8Orange25125.5
8GreenLunch14
9GreenLunch18
10GreenLunch21What I want
11GreenLunch9Green425563.75
12GreenLunch37Blue22613
13GreenLunch25Red1264264
14GreenLunch26Orange25125.5
15GreenDinner17
16GreenDessert45
17BlueBreakfast11
18BlueLunch15
19RedDinner65
20RedDinner46
21RedDinner76
22RedDinner77
23OrangeBreakfast12
24OrangeBreakfast16
25OrangeLunch23
Sheet3
Cell Formulas
RangeFormula
I4I4=COUNTIF(C4:C25,H4)
J4:J7,J11:J14J4=SUMIFS($E$4:$E$25,$C$4:$C$25,H4)
K4:K7,K11:K14K4=J4/I4
I11:I14I11=SUMPRODUCT(SIGN(FREQUENCY(IF(C$4:C$25=H11,MATCH(D$4:D$25,D$4:D$25,0)),ROW(D$4:D$25)-ROW(D$4)+1)))


You may need to enter the I11 formula with Control+Shift+Enter on your version of Excel. I'd also worry a bit about performance with 66K rows.
When I place I the formula you have for I11 in produces are result of 1 when it should produce a value of 4. Regarding the concern of performance with 66k lines, is your concern always with that many lines or is there something specific here that raises concern?
 
Upvote 0
Did you try entering the formula with Control+Shift+Enter? Select the cell with the formula, press F2, then hold down the Control and Shift keys and press Enter.

Yes, using an array formula on that many lines causes a lot of internal calculation which can slow things down. But try it and see.
 
Upvote 0
Did you try entering the formula with Control+Shift+Enter? Select the cell with the formula, press F2, then hold down the Control and Shift keys and press Enter.

Yes, using an array formula on that many lines causes a lot of internal calculation which can slow things down. But try it and see.
That worked. I missed the F2 need. THANK YOU
 
Upvote 0

Forum statistics

Threads
1,215,559
Messages
6,125,517
Members
449,236
Latest member
Afua

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