Excel Countif using month and letter as Criteria's - excel

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

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)

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:
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.

Related

Count cell per month

I look for a code for the number of times a value is in a cell, on a monthly basis
So
1-1-19 KS
2-1-19
3-1-19 KS
.
.
1-2-19 KS
2-2-19
3-2-19
January 2
February 1
is this possible?
Assume that your dates are in column A, your KS is in column B.
In cell D1:D12 you have the first of each month entered and given a custom number format of mmmm so it just shows January, February, etc.
The formula =MATCH($D1,$A:$A,0) will give the row number that the month starts on.
For simplicity I'll call this Start_Row.
The formula =MATCH(EOMONTH($D1,0),$A:$A,0) will give the row number that the month ends on.
I'll call this End_Row.
The formula INDEX($B:$B,Start_Row):INDEX($B:$B,End_Row) will set a reference in column B to all rows between the first of the month and the end of the month.
I'll call this CountRange.
Now you just need to count what's in that reference using either:
=COUNTIF(CountRange,"KS") to count just KS
=COUNTA(CountRange) to count any non-blank cells.
So the full formula, without any helper columns, would be:
=COUNTIF(INDEX($B:$B,MATCH($D1,$A:$A,0)):INDEX($B:$B,MATCH(EOMONTH($D1,0),$A:$A,0)),"KS")
Keeping in mind that D1 contains 01/01/2019

Excel SUMIFS Statement - Calculate profit for each month across multiple years

I've got three columns of data.
Sell Date - Column G - Contains the day, month and year in dd/mm/yyy format.
Month (calculated from sell date) - Column I - Contains month number
Profit - Column M - Profit in Dollars.
I am trying to calculate the profit made in each month and year.
Current formula using SUMIFS. I look at the data in Column I and if this contains a 1, and if G contains the year 2016 then it's January 2016. Think it's the year function that I don't quite get.
=SUM(SUMIFS(M9:M50, I9:I50, {"1"}, G9:G50, YEAR=2016))
You can create another column that shows just the year year(G2) or you can use this formula
=SUMIFS(M9:M50,G9:G50,">=1/1/2016",G9:G50,"<1/2/2016")
I also like this formula that allows you to reference the date in one cell and calculate a 1 month range. Put 01/01/2016 in cell A1 and the formula does the rest.
=SUMIFS(M9:M50,G9:G50,">="&A1,G9:G50,"<" & EDATE(A1,1))
The SUMIFS function doesn't like it when you alter the value of the IF parameters. It would be better to use a SUMPRODUCT formula to calculate this, for example:
=SUMPRODUCT((M9:M50)*(I9:I50=1)*(YEAR(G9:G50)=2016))
Where:
(M9:M50) are the values you wish to SUM.
(I9:I50) are the month values and 1 is the month you wish to specify.
(G9:G50) are the date values you wish to obtain the year from and 2016 is the year you are specifying.

count occurrences of a word within a date range like month or quarter

I have a sheet with data organized by date for an entire year. Column "a" would be the dates in chronological order and column "b" would have a name in each cell. Many of the names are repeated throughout the year.
What formula would I use to count how many times a particular name was listed in column b within a particular month, quarter or date range of my choice?
I would like to create a new sheet to show this data once I have the proper formula/s.
I am using excel 2016
OK, let's specify your inputs like this:
E1: name
E2: start date
E3: end date
Then to do the calculation:
=CountIf( B:B,E1, A:A,">="&E2, A:A,"<"&E3 )
So for 2016 you'd put 2016-01-01 in E2 and 2017-01-01 in E3.
(If you use "<=" and 2016-12-31 for the end of the year, you run a slight risk that a date+time combination for the last day of the year will be excluded. Better to always use lower<=x and x<upper to avoid this.)

Extracting the month value from date field array

I have a spreadsheet with two columns of dates when a customer expressed interest in buying an item and a column of dates when the sale was actually made. I am trying to sum the total amount of sales when the month on the interest matches the month of the sale. For example:
Date of Interest Date of sale Price
04/15/2015 04/15/2015 $4,795
04/09/2015 04/27/2015 $3,596
03/31/2015 04/22/2015 $6,477
04/16/2015 04/28/2015 $9,755
The formula I am trying to use is this
=SUMIFS(E2:E15,MONTH(C2:C15),H2,MONTH(F2:F15),H2)
Where E2:E15 is the column of sales amount
C2:C15 is the date of interest
F2:F15 is the column of date of sale
H2 is a field that contains a month number (4 for this example)
If the formula worked, it should return a value of $18,146 (the sale of $6,477 would not included as the interest date was in month 3)
However, I get an error with the formula (no specific information). Is there anyway to extract the month number from both columns within this formula? I can create additional columns that have the month number and if I use them the formula works.
Any help would be greatly appreciated
Try:
=SUMPRODUCT((MONTH(Lead_date) = MONTH(Sold_Date))*Sold_Amt)
or:
=SUMPRODUCT((MONTH(Date_of_Interest)= MONTH(Date_of_sale))*Price)
If you want to restrict your answer to the month number contained in H2, as suggested by #user3578951, then simply modify the above to add that factor:
=SUMPRODUCT((MONTH(Date_of_Interest)= MONTH(Date_of_sale))*(MONTH(Date_of_Interest)=H2)*Price)
If you create a helper column to create a column of months (in number form), you can use your formula. Just insert a column next to your two date columns, and use =Month(C2) and drag down. Then you can just use =sumifs(e2:e100,_[lead date helper month range]_,h2,_[sold date helper month range]_,h2).

How To automatically calculate Qtr Revenue given only two dates and Total Revenue

I could use some help writing an excel formula.
Case: Revenue is generated between 2 dates, Date A and Date B.
These dates could go into the next year and spread across quarters.
How can I split Revenue into Q1 Revenue, Q2 Revenue, Q3 Revenue, Q4 Revenue just based on my 2 dates and Total Revenue.
My thought was first identify which Qtr your dates fall into and then have an if statement that logically figures out the % and multiplies by the revenue.
Currently I'm using this formula to determine Qtr: =ROUNDUP(MONTH(DateA)/3,0).
Similarly for DateB.
Then, =if(DateAQtr=2, ((6/30/2013-DateA)/(DateB-DateA))*Revenue, 0)
There are clearly problems with this like, what happens if DateB(end Date) is in Q1 of the following year.
Denominator will always be Date B - Date A, giving you total days.
Numerator of Start Qtr is =(LastDayofQtr - Start).
Numerator of any quarters in the middle will be the full qtr length.
Numerator of End Qtr is =(EndDate - LastDayofPreviousQtr).
This is the logic. I'm trying to write into Excel formula to automate the process.
I made some named ranges to help see what is going on.
A2 = DateA, B2 = DateB, C2 = Revenue
A7 =DATE(YEAR(DateA),1,1) This is to establish the Q1 date for the DateA entered.
A8 =EDATE(A7,3) dragged down to cell A15 as in the picture. This returns the start of the next Quarter.
B7 =IF(AND(DateA>=A7,DateA<A8),A8-DateA,IF(AND(DateB>=A7,DateB<A8),DateB-A7,IF(AND(A7<DateB,A7>DateA),A8-A7))) This is checking how the dates compare to the Quarter start dates and returning the number of days our DateA and DateB date range contain for each Quarter.
C7 ="Q"&ROUNDUP(MONTH(A7)/3,0) dragged down to read the Qtr Start Date and return the corresponding Q#.
D7 =IF(B7=FALSE,"",C7&"-"&YEAR(A7)) returns the Q# and year when the days column is not false.
E7 =IF(D7="","",(Revenue/(DateB-DateA)*B7/Revenue)) This calculates the percentages of revenue that each quarter contains.
If you change the values of DateA or DateB everything still calculates properly. If you date range is larger than the two years displayed just drag the formulas down to expand the max range.
I hope this helps.

Resources