Countifs with multiple criteria

orlandotuga

New Member
Joined
Sep 29, 2017
Messages
9
Hi.

This is my first time in this forum.

I have a table in this link https://filehost.net/234a1151ff7695d3
and i cant figure a formula that works

The criteria are inside file, but i need a formula that counts products sold in each day, by year, between a min and max value. this is the easy part and i can make with a countifs formula.

BUT, in this example my products are apples and oranges and both need to meet those criteria but also must be sold in same day.

Which means apples+orange sold together in each day (does not count sold alone in a day), by year, between a min and max value.

If it looks confusing, maybe linked excel table will show what i mean. i used colors to represent which lines will be counted for each criteria.

I hope someone can help me, if some formula is possible LOL

Thank you
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Ok, so you really want to count how many DAYS within the year/store that sold both oranges and apples between a min and max.
Complicating it even more is there is a different min/max criteria for apples vs oranges.

This is going far beyond any simple adjustment to a standard countifs, and may take some time to figure out.
It may require adding columns to your layout.

Anyone else have any input?
 
Last edited:
Upvote 0
Ok, so you really want to count how many DAYS within the year/store that sold both oranges and apples between a min and max.
Complicating it even more is there is a different min/max criteria for apples vs oranges.

Yes, thats exactly what i want.


Explaining that was hard for me (my problem was finding the right words in the logic order to everything make sense)

Formula might be harder than me explaining, if even possible LOL.

I hope you (or someone else) can help me :)

I will wait. thanks
 
Upvote 0
Here's the best I can come up with so far, with lots of helper columns and cells


Book1
CDEFGHIJKL
2sales
3yearstoredataproductqtdTolerancelimitminmax
42015A12/15/2015apple2TRUEapple16
52015A1/1/2015orange3TRUEorange35
62015A10/13/2015apple5TRUE
72015A10/13/2015orange7FALSE
82015A10/15/2015apple3TRUE
92015A10/15/2015orange4TRUE
102015B10/15/2015apple3TRUE
112015B10/15/2015orange4TRUE
122016A1/15/2016apple9FALSE
132016A1/15/2016orange2FALSE
142016B1/15/2016apple4TRUE
152016B1/15/2016orange4TRUE
162016B1/15/2016apple4TRUE
172016B1/15/2016orange5TRUE
18
19
20Storedata20152016
21A12/15/201500
22A1/1/201500
23A10/13/201500
24A10/15/201510
25A1/15/201600
26B12/15/201500
27B1/1/201500
28B10/13/201500
29B10/15/201510
30B1/15/201601
31
32Total21
Folha1
Cell Formulas
RangeFormula
H4=AND(G4>=VLOOKUP(F4,$J$4:$L$5,2,0),G4<=VLOOKUP(F4,$J$4:$L$5,3,0))
E21=--AND(COUNTIFS($C$4:$C$17,E$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"apple",$H$4:$H$17,TRUE),COUNTIFS($C$4:$C$17,E$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"orange",$H$4:$H$17,TRUE))
E32=AGGREGATE(9,3,E21:E30)
F21=--AND(COUNTIFS($C$4:$C$17,F$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"apple",$H$4:$H$17,TRUE),COUNTIFS($C$4:$C$17,F$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"orange",$H$4:$H$17,TRUE))
F32=AGGREGATE(9,3,F21:F30)
 
Upvote 0
First I added column H to test for the tolerances based on apple or orange
=AND(G4>=VLOOKUP(F4,$J$4:$L$5,2,0),G4<=VLOOKUP(F4,$J$4:$L$5,3,0))

Then created a unique list of the dates in D21:D25 - repeated in D26:D30
Then each store name represented in C21:C30

Formula in E21 filled down and right is
=--AND(COUNTIFS($C$4:$C$17,E$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"apple",$H$4:$H$17,TRUE),COUNTIFS($C$4:$C$17,E$20,$D$4:$D$17,$C21,$E$4:$E$17,$D21,$F$4:$F$17,"orange",$H$4:$H$17,TRUE))

This gives a 1 or 0, 1 if the given date/store sold both apple and orange within the specific min/max tolerance.

Then you can sum those 1's and 0's to make a count
=AGGREGATE(9,3,E21:E30)
I used aggregate in E32, so it can ignore hidden rows. Therefor you can filter column C by Store.
 
Last edited:
Upvote 0
Hi.
Sorry, I couldnt reply sooner.

I've read everything and I'll replicate your tables/formulas in my excel. It would be great if it could be done without the second table, but at least now I have a working solution to count automatically the days in the excel.

Thank you so much for the help :)
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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