Counting instances between 2 dates - excel-formula

I have the following date ranges :-
01/01/2017 31/12/2017
01/06/2017 31/05/2018
01/02/2017 31/01/2018
01/01/2017 31/12/2017
01/06/2017 31/05/2018
01/02/2017 31/01/2018
Is it possible, via formula, to get a count of the ranges that include a specific date?
For example, a date of 31/01/2017 would give a result of 2 (the first and forth rows)

Use COUNTIFS:
The COUNTIFS function applies criteria to cells across multiple ranges
and counts the number of times all criteria are met.
https://support.office.com/en-gb/article/COUNTIFS-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842
So with your data in the range A1:B6 and your criteria date in cell D1:
=COUNTIFS($A$1:$A$6,"<=" & $D$1, $B$1:$B$6,">=" & $D$1)
NB: COUNTIFS is available from Excel 2007 onwards.
For Excel 2003 use:
=SUMPRODUCT(($A$1:$A$6<=$D$1)*($B$1:$B$6>=$D$1))

Related

Excel: Select Range in Formula based on column value

I have two tables that have similar columns:
Table1:
Date Ticker Data
May 2008, XYZ, 6
Aug 2010, XYZ, 5
Sep 2008, ABC, 7
Table2:
Date Ticker Data
EDIT:
* Apply SMALL formula below to ABC tickers, XYZ etc...
I'm trying to apply this formula: =SMALL($A:$A,COUNTIF($A:$A,"<="&A1))
which finds the nearest date in Table 2 from the date in Table 1
Table 2 is huge and has numerous entries of all kinds of dates and tickers.
The problem is I need to apply the SMALL formula above only to similar tickers. How do I adjust the range in the formula to ONLY apply to range with the same ticker in Table 1 and Table2? There are a few thousand so can't manually name the ranges.
Thanks!
This seemed to work for me for Excel 2010 & 2013:
{=max(if(ticker range = TICKER,if(date range <= DATE,date range)))}
CTRL+SHFT+ENTER as it is an array
I believe Excel 2016 has MaxIFS function that might make it bit easier. Will have to apply to spreadsheet and see how it works.

How do I match a date from a list of dates in Excel?

I need to compare two dates to see if they are equal from a list of dates in a column.
Eg. Sheet 1 Column A
Date 1
Date 2
Date 3
Date 4
Sheet 2 : Row F: Date 5
I want to see if date 5 is equal to any of the dates in column A and return true.
Please help me with this.
An alternative approach:
Assume Date1-Date4 are in A2:A5, and Date5 is in B2:
{=OR(B2=A2:A5)}
Note that you need to enter the formula as an array formula using Ctrl+Shift+Enter.

COUNTIFS with range criteria on different sheets

I have not read if there is a limitation with COUNTIFS function, but I am experiencing the following:
I want to count the number the number of times two conditions are true in a row. For example
Sheet 1
USERID DATE
SAM 12/1/2014
SAM 12/3/2014
SAM 12/4/2014
JON 12/3/2014
BOB 11/5/2014
Sheet 2
Dates to match against {12/3/2014, 12/4/2014, 12/5/2014}
Sheet 3
USERID DATECount
SAM 2
JON 1
BOB 0
If all this information is in the same sheet the following formula works (Assuming data in Sheet 1 is in columns A and B, and the data in Sheet 2 is in the first row D to F, and the data in Sheet 3 starts at D5.
=COUNTIFS(A:A,D5,B:B,"="&$D$1:$F$1)
Currently, to get over this, I have a SUM function and a COUNTIFS for each criteria in the range for criteria 2. But it's pretty ugly since there are 20 criteria.
What I trying to find is a more elegant way to do this, or if there is another function that can return the same results.
Note that the date range can change every month.
You need a SUMPRODUCT wrapper that will iterate the COUNTIFS results through the cells in Sheet2!$D$1:$F$1.
      
The formula in Sheet3!E5 is,
=SUMPRODUCT(COUNTIFS(Sheet1!A:A,D5,Sheet1!B:B,Sheet2!$D$1:$F$1))
Fill down as necessary.

Countifs to match OR conditions?

I have the following countifs formula
=COUNTIFS($F$2:$F$848,Summary!$F5,'Report'!$G$2:$G$848,$Q$10,$G$2:$G$848,$Q$11)
on my sheet, Q10 = Monday, Q11 = Tuesday
On 'Report', G2:G848 contains login data
Objective: I need the total count from Report that are either on Monday(Q10) or Tuesday (Q11)
With the current formula I have, countifs is looking for rows that has Monday and Tuesday in the row, which is a wrong.
How can I solve this ?
Presumably F2:F848 is also on Report sheet? Try this
=SUMPRODUCT(COUNTIFS('Report'!$F$2:$F$848,Summary!$F5,'Report'!$G$2:$G$848,$Q$10:$Q$11))
Assumes formula resides on same sheet as the Q10 and Q11 values....
The COUNTIFS function will return an "array" of 2 values, one for Monday (Q10) and one for Tuesday(Q11), then SUMPRODUCT just sums the 2 values to give you the total for both days
=COUNTIF('Report'!$G$2:$G$848,"Q10")+COUNTIF('Report'!$G$2:$G$848,"Q11")
This assumes that 'Report'!$G$2:$G$848 contains the Q10 and Q11 values you're talking about.

Use date as a criteria in SUM or sumif function

I have two columns
Amount Date
100 01/01/2000
2000 01/12/2002
2000 02/02/2005
150 03/02/2000
250 05/03/2002
350 04/05/2006
I need result as follows
Total year
2005 - 2000
2000 - 250
2002 - 2250
2006 - 350
Can I use SUMIF function for this? If it's possible what criteria I have to put?
You can use the same formula as described in this thread: Summarize grouping by year and month
=SUMPRODUCT((YEAR(Sheet1!$B$2:$B$6)=A2)*Sheet1!$A$2:$A$6)
I supposed your data are in an array from A1 to A6 on Sheet1 and your results are on another Sheet, you put the year in column A and the formula in column B
If you add a column to the right of the date column containing
=year(B2)
(replace B2 with whichever cell contains the date in that row)
and fill that column down, then you can do a standard sumif on that column like
=sumif(C2:C10, 2002, A2:A10)

Resources