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

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

Related

In Excel how to count between date1 and date2 that have cells in row that contain text?

I need to choose cells in one column that are between two dates, and then based on the rows that contain those dates, choose cells in another row that also contains content.
I didn't use ISBLANK because it counts a formula yet an empty cell as a not-blank. Instead check if there is content by "*".
Here is what I came up with, but instead of returning the number of cells, instead this returns TRUE (which obviously isn't what I want).
In the formula below I am assuming:
C:C is the whole column containing DATES.
E:E is the whole column containing CONTENT.
The date range in this case is January 1, 2018 to January 31, 2018.
"*" means is there is content in the cell
=IF(AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*"))=0,"",AND(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&"2018-1-31"),COUNTIF(E:E,"*")))
My goal is to:
count the numbers of the cells in column E that are between the dates in column C
if the whole formula is 0, then return a blank.
See this picture of a sample excel sheet to make my intent clear:
How can I get my formula working so it does as needed?
SOLUTION
Hi all, so thanks to #girlvsdata, we have a working solution. I had to do a couple edits to her code to work for my uses, but her formula overall works perfect. Here is the solution:
To choose all cells in column E that are not blank, in between the date range of all of January (unknown end date) based on the adjacent C column if that is your date column, then the solution is:
=IF(COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*")=0,"",COUNTIFS(C:C,">="&"2018-1-1",C:C,"<="&EOMONTH("2018-1-1",0),E:E,"*"))
Note that "2018-1-1" is January 1 2018, and EOMONTH("2018-1-1",0) is the last valid day of January in the year 2018 (in this case, 31, but if it is different another year (e.g. for February this works for leap years too) then it will be that last day). Also it eliminates the need to calculate which is the last day or every month, as well as months that have changing end dates dependent on the year (e.g. Feb). This is important to eliminate a margin of error.
The only thing you have to do to change the month is only change e.g. -1- (Jan) to -2- for Feb, or change the year for other years. With this formula you can ignore the day part.
If the answer is 0 (no cells have any content in between the range), then the cell is blank instead of 0. (GOod for when you want to create a sheet checking future dates for future reference when more rows are added to the sheet.
It also works across different sheets, just use, say your other sheet is called "Tracker" then use Tracker!C:C and Tracker!E:E. Hope it helps!
Thank you all! :D
(Please note: My local date format is day, then month)
With the data laid out as in your example above:
A B
1 Dates |Content
------------+-------
2 1/01/2018 |
3 2/01/2018 |123456
4 3/01/2018 |
5 4/01/2018 |12398
6 5/01/2018 |484
7 6/01/2018 |1538
8 7/01/2018 |
9 8/01/2018 |
10 9/01/2018 |
11 10/01/2018 |14648
12 11/01/2018 |
13 12/01/2018 |145615
14 13/01/2018 |
And with the date range in cells D2 and E2:
Date Start Date End
2/01/2018 7/01/2018
This formula returns the count:
=COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")
This will depend on whether your numbers in Column B are formatted as text or number. If they are formatted as numbers, the above formula will work. If they are formatted as text, replace the last section ">0" with "*".
This formula adds the conditional part of your question:
=IF(COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0")=0,"",COUNTIFS(A:A,">="&D2,A:A,"<="&E2,B:B,">0"))
(If the formula returns 0, show blank)

VBA, change part of date in cell

I have a large sheet of data where i need to change the date (day) in 4 or 5 columns to match the date (day) in another column. For example in 'H' i have 16/05/15 etc. and in the other columns all the days are the 1st of the same month. I would like to change the day '1' to the same day '16' as in column 'H' it will take me hours to do, can anyone help me out with some code that would do it for me?
Thanks.
If this is a one-off, you could just write a formula in a temporary column that calculates DATE using the YEAR and MONTH of the original cell and the DAY of column H (watching out for 29th of Feb in non-leap years, if the year in H is different to the year in the other cell), and then "paste values" that result back over your original cells.
For example, assuming data you want to change is currently in K2, then place the following formula in X2 (or wherever else you like):
=IF(MONTH(DATE(YEAR(K2),MONTH(K2),DAY(H2)))<>MONTH(K2),
DATE(YEAR(K2),MONTH(K2)+1,0),
DATE(YEAR(K2),MONTH(K2),DAY(H2)))

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.

Excel - how to get if a date is a specific day of the week?

I have a spreadsheet that tracks average file processing times over the course of a month. One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). The spreadsheet is organized into columns by weekdays of the month:
The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value.
Currently, I just have to manually tell the Macro which columns are Mondays, like so:
=AVERAGE(B20,G20,L20,Q20)
So, instead of manually, how would I get the average over the range of say, B20 to V20, only if the day of the week is Monday (the date cells are in row 1, so B1 to V1)?
To determine the weekday of a date in EXCEL use the =WEEKDAY() formula, which evaluates as 1 (Sunday) to 7 (Saturday)
e.g. If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1) would evaluate to 7 (indicating that the last day of 2016 was a Saturday)
To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2)
insert a new row to hold the WEEKDAY() value (say, row 2)
in cell A2 type in =WEEKDAY(A1)
copy this formula as far right as necessary (to include all your dates)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)
Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day.
TEXT(B4,"dddd")
Then add an 'If'statement to your result cell.
simply
=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)
should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday.
the first part sums the values of all mondays and the second part counts them (sum / count = average) ;)
If you have any questions, just ask.
If your date is in A1, you can use =Text(A1,"dddd") to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps:
=If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (may need a helper row/column to hold the text of the weekday)
(Or use AverageIf() and use the Text() idea.)

Excel Countif using month and letter as Criteria's

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.

Resources