Home » excel » DATEDIF on a Range in Excel

# DATEDIF on a Range in Excel

Questions:

I have an Excel table with 2 columns for Created Date and Closed Date. I’m trying to get a count of records within a certain range of lifetime values (lifetime = # days between Created and Closed Date). So for example, how many records have a lifetime of 40+ days.

I can’t modify the table to add new columns (I’m trying to do my calculation off in a separate sheet without modifying the main sheet with the data).

What I tried to do is this:

``````=COUNTIF(DATEDIF(MyTable[CreatedDate], MyTable[ClosedDate], "d"), "> 40")
``````

That formula doesn’t work, I believe for a couple of reasons: You can’t pass ranges to DATEDIF, also DATEDIF returns a discrete value but COUNTIF expects a range.

It appears that what I’m trying to do obviously doesn’t work on Ranges. Is there a way to do a DATEDIF between two Ranges, that then returns a new Range so that I can COUNTIF it? Or some other way to accomplish my goal?

Some Sample Data (Lifetime is not an actual column in my table, just included here for convenience):

``````Created Date      Closed Date      Lifetime
9/20/2012         10/19/2012       29
9/20/2012         10/27/2012       37
9/20/2012         12/26/2012       97
9/20/2012         10/23/2012       33
9/20/2012         11/23/2012       64
10/19/2012        12/14/2012       56
``````

Note: Every record will have a valid Created and Closed Date.

UPDATE: @pnuts suggested a formula that may or may not work:

``````=COUNTIF(MyTable[ClosedDate], ">"&MyTable[CreatedDate]+40)
``````

I’m not sure exactly what’s going on, but depending on what cells in my worksheet I put that formula in I get different results. Here’s a screenshot, every cell has an identical formula as shown in the formula bar.

If anybody wants to try it out in my sample Excel file, you can grab it here: Sample Excel File

Note that @pnuts’ formula works if you use it as an array formula, i.e. if you use Ctrl+Shift+Enter.

A non-array formula you can use is:

``````=SUMPRODUCT(((Table1[Closed Date]-Table1[Created Date])>40)*1)
``````

`Table1[Closed Date]-Table1[Created Date]` is the difference between dates and when you put `>40` after it, you will get a series of boolean (True/False) and the `*1` at the end converts the True to 1 and the False to 0. `SUMPRODUCT` adds them all up.

`=SUM(IF((Table[ClosedDate])-(Table[CreatedDate])>=40,1,0))`