Countifs variable crietera, avoid hardcodes?

Will85

Active Member
Joined
Apr 26, 2012
Messages
254
Office Version
  1. 365
Platform
  1. Windows
Sheet1 Column A has values throughout, the values are "Apples", "Oranges", "Cookies", "Apples"
Sheet 2 has a table, A1 = Apples, B1 = Healthy, A2 = Oranges, B2 = Healthy, A3 = Cookies, B3 = Unhealthy, A4 = Apples, B4 = Healthy
Sheet 3 A1 = Healthy, B1 = Unhealthy


A2 & B2 = I need a formula to count the number of times a Healthy or Unhealthy value appeared in Sheet1 Column A

I dont want hardcodes, I might change the value in Sheet2 Column B, so I need it to be dynamic. I think I want a countif array formula, but I am struggling.
 
Using the table definition will be easier to understand debug and most resource efficient. But, you have a solution that works so that is good.
As far as the month, it would just be one more parenthetical comparison statement in the formula. I'll post a formula in a moment. But again, this brings me back to my historical data integrity questions I made earlier. By changing your Legend you are messing up prior reports that use the same legend source. but if you want to see the updated health statuses looking back then this works. Hold on for an updated formula for months included.
I appreciate your concern, this is obviously just test data. My real world situation is not concerned about historical, but I do appreciate your attention to detail. Ill look out for your update.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
OOF, that really added more complexity to it. I needed to use some functions that are only in Office 365.
But here it is.

mr excel questions 29.xlsm
ABCDEFGHI
1DataMonthFoodRatingHealthyUnhealthy
2CookiesDecemberCookiesHealthyJanuary1613
3ApplesNovemberApplesUnhealthyFebruary1714
4CookiesMayOrangesHealthyMarch1110
5OrangesNovemberPearsUnhealthyApril1312
6PearsDecemberWatermelonUnhealthyMay1511
7ApplesMarchCandyHealthyJune118
8CookiesNovemberSRFUnhealthyJuly109
9PearsJunePCKHealthyAugust1413
10WatermelonMayCQWHealthySeptember1414
11CandyAugustHDOHealthyOctober1415
12CandyAugustONYHealthyNovember118
13ApplesAprilJXRUnhealthyDecember1116
14SRFMaySIJUnhealthy
15PCKSeptemberJGGHealthy
16CQWFebruaryJMHUnhealthy
17HDOMarchRXVUnhealthy
18ONYAugustFDPHealthy
19JXRJuneXSQUnhealthy
20SIJJulyOWIHealthy
21JGGAprilTLGUnhealthy
22JMHJulyNLEUnhealthy
23RXVAprilPicklesHealthy
24FDPJanuaryTomatoesHealthy
25XSQJanuaryJelly BeansHealthy
26OWIJuly
27TLGAugust
28NLEApril
29PicklesJune
30NLEOctober
31Jelly BeansJanuary
32CookiesNovember
33ApplesAugust
34CookiesAugust
35OrangesMarch
36PearsJanuary
37ApplesNovember
38CookiesJanuary
39PearsAugust
40WatermelonFebruary
41CandyJuly
42CandyJuly
43ApplesDecember
44SRFOctober
45PCKSeptember
46CQWFebruary
47HDOMay
48ONYFebruary
49JXRMarch
50SIJDecember
51JGGDecember
52JMHJanuary
53RXVOctober
54FDPDecember
55XSQJanuary
56OWIAugust
57TLGApril
58NLEMay
59PicklesJune
60TomatoesJuly
61CookiesDecember
62ApplesMay
63CookiesNovember
64OrangesMarch
65PearsMarch
66ApplesDecember
67CookiesAugust
68PearsJune
69WatermelonOctober
70CandyFebruary
71CandyFebruary
72ApplesFebruary
73SRFApril
74PCKOctober
75CQWOctober
76HDOSeptember
77ONYOctober
78JXRSeptember
79SIJDecember
80JGGMarch
81JMHMay
82RXVSeptember
83FDPDecember
84XSQSeptember
85OWINovember
86TLGOctober
87NLEJuly
88PicklesFebruary
89TomatoesSeptember
90CookiesAugust
91ApplesOctober
92CookiesMarch
93OrangesFebruary
94PearsNovember
95ApplesFebruary
96CookiesMay
97PearsDecember
98WatermelonFebruary
99CandyFebruary
100CandyJanuary
101ApplesSeptember
102SRFAugust
103PCKAugust
104CQWJune
105HDOJune
106ONYSeptember
107JXRAugust
108SIJJune
109JGGOctober
110JMHSeptember
111RXVMarch
112FDPMay
113XSQJuly
114OWIMay
115TLGDecember
116NLEFebruary
117PicklesDecember
118TomatoesFebruary
119Jelly BeansSeptember
120CookiesJanuary
121ApplesAugust
122CookiesFebruary
123OrangesAugust
124PearsJanuary
125ApplesJanuary
126CookiesNovember
127PearsMay
128WatermelonAugust
129CandyJanuary
130CandyApril
131ApplesJuly
132SRFDecember
133PCKAugust
134CQWMarch
135HDOFebruary
136ONYMay
137JXRFebruary
138SIJOctober
139JGGJuly
140JMHDecember
141RXVNovember
142FDPDecember
143XSQAugust
144OWIJanuary
145TLGMay
146NLESeptember
147PicklesJune
148TomatoesOctober
149Jelly BeansMay
150CookiesMay
151ApplesJuly
152CookiesOctober
153OrangesMarch
154PearsMay
155ApplesJanuary
156CookiesSeptember
157PearsOctober
158WatermelonApril
159CandyDecember
160CandyOctober
161ApplesAugust
162SRFJune
163PCKJuly
164CQWAugust
165HDOMay
166ONYDecember
167JXRDecember
168SIJOctober
169JGGJanuary
170JMHSeptember
171RXVDecember
172FDPApril
173XSQOctober
174OWISeptember
175TLGJanuary
176NLEOctober
177PicklesJanuary
178TomatoesJanuary
179Jelly BeansNovember
180CookiesJune
181ApplesApril
182CookiesApril
183OrangesNovember
184PearsJanuary
185ApplesSeptember
186CookiesFebruary
187PearsDecember
188WatermelonFebruary
189CandyJuly
190CandyApril
191ApplesJuly
192SRFJune
193PCKMarch
194CQWApril
195HDOAugust
196ONYOctober
197JXRApril
198SIJDecember
199JGGApril
200JMHMarch
201RXVOctober
202FDPJanuary
203XSQSeptember
204OWIMay
205TLGSeptember
206NLEMarch
207PicklesMay
208TomatoesAugust
209Jelly BeansMay
210CookiesOctober
211ApplesMay
212CookiesJanuary
213OrangesOctober
214PearsJanuary
215ApplesMay
216CookiesMay
217PearsSeptember
218WatermelonDecember
219CandyJuly
220CandySeptember
221ApplesFebruary
222SRFFebruary
223PCKApril
224CQWMay
225HDOOctober
226ONYApril
227JXRAugust
228SIJNovember
229JGGJune
230JMHNovember
231RXVDecember
232FDPSeptember
233XSQJuly
234OWIOctober
235TLGFebruary
236NLENovember
237PicklesNovember
238TomatoesOctober
239Jelly BeansApril
240CookiesJune
241ApplesOctober
242CookiesFebruary
243OrangesFebruary
244PearsFebruary
245ApplesMarch
246CookiesJune
247PearsMarch
248WatermelonSeptember
249CandyMay
250CandyAugust
251ApplesJuly
252SRFJune
253PCKJune
254CQWApril
255HDOSeptember
256ONYMarch
257JXRFebruary
258SIJApril
259JGGFebruary
260JMHNovember
261RXVSeptember
262FDPMarch
263XSQJune
264OWIOctober
265TLGAugust
266NLEMay
267PicklesJanuary
268TomatoesApril
269Jelly BeansJanuary
270CookiesFebruary
271ApplesSeptember
272CookiesNovember
273OrangesNovember
274PearsJanuary
275ApplesApril
276CookiesJanuary
277PearsMarch
278WatermelonFebruary
279CandyFebruary
280CandyDecember
281ApplesJanuary
282SRFFebruary
283PCKMarch
284CQWApril
285HDOSeptember
286ONYSeptember
287JXRAugust
288SIJDecember
289JGGJuly
290JMHAugust
291RXVJanuary
292FDPDecember
293XSQApril
294OWIJuly
295TLGApril
296NLEOctober
297PicklesSeptember
298TomatoesJune
299Jelly BeansJanuary
300TLGMarch
301NLEOctober
WillB85
Cell Formulas
RangeFormula
H2:I2,I3:I13H2=LET(a,FILTER(Data,Data[Month]=$G2,""),b,TAKE(a,,1),c,INDEX(Legend[Rating],MATCH(b,Legend[Food],0)), d,SUM(--(c=H$1)),d)
H3:H13H3=LET(a,FILTER(Data,Data[Month]=G3,""),b,TAKE(a,,1),c,INDEX(Legend[Rating],MATCH(b,Legend[Food],0)), d,SUM(--(c=H$1)),d)
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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