transcript

excelisfun - Excel Magic Trick 1390: Average Number of Days Between Dates in a Single Column 3 Examples

Thumbnail of the video “excelisfun - Excel Magic Trick 1390: Average Number of Days Between Dates in a Single Column 3 Examples”
Download Markdown
Community upload. AI output has not been independently verified.

Welcome to Excel Magic Trick number 1,390. If you want to download this Excel workbook, Excel Magic 1,389 to 90, so you can follow along, click on the link below the video. Last couple of videos, 1,388 and 1,389, we've been talking about average number of days between dates. Now in this video we want to talk about average number of days between a single column of dates.

In the last two videos we had two separate columns, an end date and a begin date, but here we have a sequential list, so we want to calculate the difference between the first two, then the next two, and next two, and so on. Calculate all the differences and then calculate an average.

Well, if we're going to use a helper column, we're not going to have a formula in the first cell, but in the second cell we say, hey, equals the later date minus the earlier date, which is the cell above it. Press Control+Enter to calculate the difference, then copy it down. Once I have my actual differences, I can come down here and use the AVERAGE function. I'm using the helper column here, simply taking those numbers, adding them up, and dividing by the count. So 3.2 is the average number of days between each one of these dates.

Now, if we didn't want to use a helper column, we can notice something here: blue cell minus orange cell. As we go down, it looks like it's always trying to take whatever the one is here and subtract the one above. If we wanted a single-cell formula, we could jump straight to the AVERAGE function, and inside the Number1 argument we have to simulate this helper column. So I'm simply going to take the full column of later dates and subtract, staggering the reference one above the earlier dates. What that means is B11 will subtract B10, so B11 minus B10 gives me that one. Then it goes to B12 minus B11, and so on. Now we can click on the argument inside AVERAGE and press the F9 key to evaluate and verify that the helper column is being simulated by our array calculation inside AVERAGE. Control+Z.

The one downside of any array calculation is that if you have very large data sets, they can take a long time to calculate. Why is this an array operation? Because it's not a single cell minus another single cell; it's an array of items minus another array of items. In order to get this formula to calculate correctly, we have to close the parentheses, but the AVERAGE function's Number1 argument will not know how to calculate this array operation unless we tell Excel this is an array formula. The way we tell Excel is when entering the formula, we hold Control and Shift and then press Enter. Immediately after, we look up to the formula bar to verify that the curly brackets were automatically added by Excel. Those curly brackets are Excel telling you it understood that the formula should be calculated as an array formula.

So we have our helper column and our array formula. We can also take a page from 1,389 and do three separate aggregate calculations. I'm going to type the equals sign, open parentheses, and SUM. I'm going to add, in essence, the later dates, close parentheses, minus the sum, in essence, of the earlier dates. If we're allowed to do this calculation all at once, we can certainly add them all and then subtract all of the orange ones, the earlier dates, and close the parentheses. We want the subtraction to happen first, so we have our parentheses, then divide by the count. Be careful that we don't want the whole column; we want the whole column in essence minus one, so we close the parentheses.

The advantage to this is that we don't have to use Control+Shift+Enter and we don't need a helper column. Although I didn't time these, I have a sneaking suspicion the array calculation would take a lot longer to calculate with a big data set. When I hit Enter, there's some number formatting being misapplied, so I immediately go up to the Number group, click the drop-down, and select General. Remember, General number formatting is like an eraser that removes the other types of number formatting. Or we can use the keyboard shortcut for General: Control+Shift+Grave Accent (Tilde).

All right, that was a lot of fun calculating the difference between a single column of dates, taking those differences, and then calculating the averages. We'll see you in the next video.