Count if date range fits within other date range - excel

I have a set of data with names of people who are on vacation for certain dates (Name, Start, End).
Example:
Name Start End
Joe 10-Jan-14 21-Jan-14
Billy 12-Feb-14 10-Mar-14
David 11-Jan-14 20-Jan-14
Patty 10-Jan-14 19-Jan-14
Megan 05-Jan-14 20-Jan-14
-------------------------------
Block 15-Jan-14 22-Jan-14
I want to count the number of people in the range who are going to be on vacation during the block dates. It should return 4; Joe, David, Patty and Megan.
The formula I have is:
=COUNTIFS(colStart, ">="&B1, colEnd, "<="&B2)
colStart and colEnd are named ranges of the Start and End column.
B1 and B2 are the block dates on my spreadsheet.
My problem is that it won't count someone who started before the block start date or ends after the block end date.. even though they will be on vacation during some point in the block dates. Joe, for example.. starts on 10 Jan. He will be on vacation still during the block dates.
Visually I am comparing number lines. I just need help to translate that to code.

Just turn your formula round a little.
If the start date is equal to or earlier than B2 AND the end date is greater than or equal to B1 then there must be some sort of overlap of the periods - if one or other of those conditions doesn't hold then there is no overlap, hence this formula gives your count
=COUNTIFS(colStart,"<="&B2,colEnd,">="&B1)

Here's how to view it from the opposite side of Jerry's answer. You have two scenarios that you don't want.
Start date after your block
End date before your block
Count all the dates and exclude those two.
=COUNT(colStart)-SUMPRODUCT((colStart>blkEnd)+(colEnd<blkStart))

Let's assume Start date reference is on B1 and End date reference is on B2.
Also, consider that the dataset header starts on cell A4 (Name) and first row of data is #5.
Type on D5 (and drag the formula down):
=IF(OR(AND(B5>$B$1,B5<$B$2),AND(C5>$B$1,C5<$B$2),AND(B5<$B$1,C5>$B$2)),1,0)
Then, in any cell:
=SUM(D5:D9)

Related

Only calculate when finished entering week

I needed help generating a formula week wise. My goal is to have the First Contact (FC) and Follow-up (FU) calculated from Wednesday of a week to the Tuesday of next week by looking at the dates. So, in this case on cell M10 the FC should be 5 and on cell N10 the FU should be 3 and then again it would calculate for the next week from Wednesday until Tuesday so on M16 it should calculate FC as 1 and on N16 the FU as 4.
I need to continuously record data for further weeks therefore need a formula which could do so. Would a SUMIF be a good option here?
Currently I have the following formulas:
=COUNTIF(A:A,"First Contact") which calculates 6
=COUNTIF(A:A,"Follow-up") which calculates 7
Formula in cell C2:
=IF(A2<>"";"";COUNTIFS(A:A;"First Contact";B:B;"<="&B1;B:B;">="&B1-6))
Formula in D2:
=IF(A2<>"";"";COUNTIFS(A:A;"Follow_up";B:B;"<="&B1;B:B;">="&B1-6))
Drag to bottom.
Since your data is sorted you could use the following:
In M10 use: =COUNTIF($A$1:$A10,"First Contact")-SUM(M$1:M9)
And in N10 use: =COUNTIF($A$1:$A10,"Follow-up")-SUM(N$1:N9)
And since your results show in an empty row, if you want a draggable solution, wrap it in IF like this: =IF($A10="",COUNTIF($A$1:$A10,"FC")-SUM(M$1:M9),"")
The $ in the range reference for column letter and row number will lock the position if you drag the formula or copy it and paste it elsewhere.

How to do a running count of dates within a date range in excel?

I am trying to build a formula in excel, that will do a running count of dates within a specified date range for an item. For example: Item A has a Start Date of 7/15 and an End Date of 7/18. I need a formula that will "tally" or add "1" to a running count for 7/15, 7/16, 7/17, 7/18 in another column that has a comprehensive list of dates. How can I do this?
EXAMPLE ATTACHED AS LINK
Well... Some examples would be helpful, but it sounds like you're looking for countifs.
If we create two excel tables, one called Items with Start and End dates:
Title Start End
ItemA 7/15/2017 7/18/2017
ItemB 7/16/2017 7/20/2017
And one called Dates which counts the Items
Date Count
7/15/2017 1
7/16/2017 2
7/17/2017 2
7/18/2017 2
7/19/2017 1
7/20/2017 1
Then our formula in the Count column of Dates would be
=COUNTIFS(Items[Start],"<="&[#Date],Items[End],">="&[#Date])
In plain english, this is saying "Count all items in Table Items where the value in the Start column is less than or equal to the value in my Date column and the End column is greater than or equal to the value in my Date column. Note that these formulas are entirely in Excel Table format, which makes for more readable formulas. If we want A1 notation, we will assume that the Items table starts at A1, which would result in the following formula:
=COUNTIFS($B$2:$B$3,"<="&$E2,$C$2:$C$3,">="&$E2)

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

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

Frequency of data occurence in Excel Column based on the certain condition

I have a column (Table 1 below) with time data in 24 hour format saved as text.I want Table 2 to be populated by the hour and adding all the occurrences for the hour.
So one occurrence is at 0102. This falls within an hor range of 12:30am to 01:30pm. I want the count to be 1 for 01:00.
If an occurrence falls between 01:30 to 02:30 I want the count to be 1 for 02:00.
Also if time is 04:55 it should show count for 05:00 as 1. Basically rounding to the closest time and showing a count for that. It should round of to the nearest time and add the number of occurrences also. Thats why 06:00 is 2. to account for 0622 and 0614.
For example:
TABLE 1 TABLE2 (Expected results)
Column A Column A Column B
0102 01:00 1
0222 02:00 2
0223 03:00 0
0455 04:00 0
0622 05:00 1
0614 06:00 2
NOTE In B1 we get 1 because value in A1 of TABLE1 is 0102 and falls between 12:30 and 01:30, thus represented by 01:00 in A1 in TABLE 2. We have two values in Table1 between 01:30 and 02:30: one is in A2 and the second is in A3, so we expect 2 in B2 in TABLE 2, the time range which is represented by 02:00 in A2. We attribute 0 to cells B3 and B4 in Table2 because there isn't any data in Table1 between 02:30-03:30 and 03:30-04:30, therefore they get 0 in their corresponding cells in Table2. However, we have two instances of data, 0622 and 0612 in Table1 which fall between 05:30 and 06:30, so value 2 is attributed to B6.
How do I do this using a formula?
Please help.
So after struggling to understand what was going on, here is the simple solution:
first let me clarify again:
column A: but pasted as text originally and in hhmm format, but you need to reformat them as simple numbers, so you will lose those 0 s at the beginning of certain data.
column B: we put down our time ranges, as you said, starting from 12:30 AM, so i put it down as 0030 of which the zeros are not visible anymore in number format. This range starts from 30 and increments by 100, until it stops at 2330 instead of going to 2430. this will be reflected in the formula for the last cell in column D.
column C: the hour ranges against which we round and count the data in A.
column D: we put down the following formula in D2 :
=COUNTIFS(A:A,">"&$B2,A:A,"<"&$B3)
and drag and fill down until the last but one cell.
for the last cell D25 we change the greater/smaller than signs, and use the following formula (only for this cell):
=COUNTIFS(A:A,"<"&$B25,A:A,"<"&$B2)
Try these formulas, if it doesn't work, download the example sheet,
here is the example sheet i created for this purpose, downloadable from here
and if you still have questions, don't hesitate to put them in the commentaries.

Resources