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
 
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.
Very clever. I never thought about using SIGN function as a condition in that construction. I had always forced a 1 in an IF function. This is a keeper.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,026
Messages
6,122,743
Members
449,094
Latest member
dsharae57

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