Question

I have a list of sales data that includes the date of the sale and also a sales type code. I'm trying to use COUNTIFS to count how many sales of a specific type there were during each month .

So for example:

Date.                  Sales Type Code
10/01/2014.                 S
12/01/2014.                 S
15/01/2014.                 O
18/01/2014.                 S
02/02/2014.                 O
08/02/2014.                 S

Would give me the following results:

Code S

January -       3    
February -      1

Code O

January -       1
February -      1

I have the formula

COUNTIFS('SALES LEDGER'!A:A,F2,'SALES LEDGER'!C:C,"<"&EOMONTH('MONTH Sales by Sales Type'!$C$1,0)+1)

Where A:A is the list of Sales Type Codes, F2 is the code I want to count, C:C is the list of dates and C1 is the first of the month I want to count (ie. 01/01/2014).

This works fine for January, giving me the expected result. But when I change C1 to 01/02/2014, it counts January and February together, rather than just February.

If anyone has any suggestions it would be appreciated!

Thanks

Était-ce utile?

La solution

Your COUNTIFS formula specifies an end date but no start date, if you want to count for a specific month and year (based on C1) you need another criterion to specify the start date using C1, i.e.

=COUNTIFS('SALES LEDGER'!A:A,F2,'SALES LEDGER'!C:C,"<"&EOMONTH('MONTH Sales by Sales Type'!$C$1,0)+1,'SALES LEDGER'!C:C,">="&'MONTH Sales by Sales Type'!$C$1)

Autres conseils

You could use this one (if your range with dates doesn't contain empty cells):

=SUMPRODUCT((MONTH(A2:A100)=1)*(B2:B100="S"))

or (if your range could contain empty cells)

=SUMPRODUCT((TEXT(A2:A100,"mmm")="Jan")*(B2:B100="S"))

If you need to add also year condition, just add *(YEAR(A2:A100)=2014) in any formula:

=SUMPRODUCT((TEXT(A2:A100,"mmm")="Jan")*(YEAR(A2:A100)=2014)*(B2:B100="S"))

Assuming:

  • it is amenable to use helper columns
  • Dates in col A
  • Sale Type Codes in col B
  • Results placed from A9:C11

Screenshot:

enter image description here

Add a helper col C to extract Month from date. Add this formula in C2 and drag down:

=TEXT(A2,"Mmm")

Add this formula in B10 and drag down and across:

=COUNTIFS($B$1:$B$7,B$9,$C$1:$C$7,$A10)

with the code below you can retrieve the month each date is in:

dim objDate as Date
dim i as integer
dim intMonth as integer

for i = 2 to 'number of row
    objDate = CDate(cells(i, 1))
    intMonth = Month(objDate)
next i

After figuring out the month with a simple loop you can count the number of sales in each month.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top