I am trying to make data collected in 15 minute increments look like data collected in 5 minute increments with the blank spaces being zero. I have created a column with Julian
The common way to handle this sort of lookup is using INDEX-MATCH
. You may also be able to use VLOOKUP
but I always prefer INDEX-MATCH
.
Picture of ranges shows the 5 minute times in column C
with 15 minute data in column F
.
Formula in C1
is a combination of INDEX-MATCH
and IFERROR
. The IFERROR
is used to handle the case of a value not found and returning the 0
you wanted.
=IFERROR(INDEX($F$1:$F$11,MATCH(B1,$E$1:$E$11,0)),0)
That formula can be copied down from C1 to the end of the 5-minute times.
Your sample formula looks like it uses different columns that your narrative describes. I will use what I understand from your description as the columns. See my sample image below for clarity.
Time lookups are prime candidates for 15 digit precision floating point errors. This is due to the base nature of time being a decimal portion of a day and the repeating decimals inherent with displaying 60 minutes and 24 hours. This problem is often magnified by using incremental progression vs datum growth.
If you have a base time in A2 and wish to create a series of 15 minute increments from that to fill down the column, do not use something like the following:
=TIME(0,15,0)+A2 ◄ generates incremental error growth
When you fill that formula down, any error is multiplied as you fill down. Your base display of minutes may not show any obvious errors but if it was displayed as seconds you would likely find that an extra second was added or subtracted every several hundred rows. This is known as Incremental Error Expansion where each successive row adds to the error generated by the previous formula. In short, if you have a hundred of these formulas in a column, any error in the first is multiplied by 100 by the last one.
By always basing the sequential time formula on A2, the error is minimized to a single calculation. Change the formula to something like,
=TIME(0,ROW(1:1)*15,0)+A$2 ◄ datum growth based on minutes added to A2
Even with a datum growth formula you may have some errors on exact matches. Best to wrap the formula in an MROUND function that allows you to round off the returned value to a specified multiple; in this case to the nearest second.
=MROUND(TIME(0, ROW(1:1)*15,0)+A$2, TIME(0, 0, 1))
Fill down to get a progressive column of values with a 15 minute increment. You will likely not see any difference in the displayed values but the raw underlying value that is used for the lookup will be quite different. This principle is know as Datum Incrementing; e.g. all progressive numbers are based on a single calculation against the original.
So with a time value in A2 these are the formulas that should be used.
8:30:00 AM ◄ starting time value in A2
=MROUND(TIME(0, ROW(1:1)*15,0)+A$2, TIME(0, 0, 1)) ◄ in A3 add 15 minutes to A2 (fill down as necessary)
=A2 ◄ starting time value in C2
=MROUND(TIME(0, ROW(1:1)*5,0)+C$2, TIME(0, 0, 1)) ◄ in C3 add 5 minutes to C2 (fill down as necessary)
These will produce the most accurate time increments to be used for an exact match lookup.
Now you can apply a VLOOKUP function or an INDEX function paired with a MATCH function to retrieve the values from column B. An IFERROR function will catch non-matches and output a 0 instead of the #N/A
error.
My formula in column D uses an INDEX/MATCH pair. D2 is,
=IFERROR(INDEX($B:$B, MATCH(C2,$A:$A, 0)), 0)
There is an alternate formula in E2 using VLOOKUP,
=IFERROR(VLOOKUP(C2,$A:$B, 2, FALSE), 0)
Caveat: There is a maximum number of minutes that can be applied with the TIME function. This is the maximum positive value of a signed integer or 32,767 (about 22¾ days worth of minutes).
You could eliminate the look-up altogether and just use the index function to reference the cells needed like this:
Regarding Is a comment warning enough when dealing with potential data loss? and =TIME(0,ROW(1:1)*15,0)+A$2
I caution that applied ‘liberally’ there may be the risk of loss of data. May depend on machine specifications etc. but trying to fill most of a column with that formula my Excel crashed (after attempting for most of 1-1/2 hours). I’d be interested in the experiences of others, in part because dealing with the least significant digit might be processor dependent.
On my machine I tried comparing:
=TIME(0,ROW(1:1)*15,0)+A$2
with
=TIME(0,15,0)+B2
Over 1,000 rows (ie about 10-1/2 days of quarter hours) and found differences (computed, so a possible source of further inaccuracy). The main difference being that the latter accounts for day changes (the integer part in Number format) whereas the former does not. Allowing for integer differences over 1,000 data points there were about 30 that differed by 0.00000000000003
, in Number format, and a further 10 or so by much smaller amounts.
The last data point (09:45 AM on day 10) was one of those exhibiting the larger difference (though not as the accumulation of a series of smaller differences). Any difference can be enough for a failure to make an exact match but in seconds that is a difference of about 0.000000002592
by my reckoning, say ~0.0000026
milliseconds or ~26
nanoseconds.
Since in my opinion the day (integer part) is likely to be useful, I would recommend series fill by entering 0
in one cell and 00:15:00
in the next, the dragging down to suit. This has no performance impact because the cell contents are values rather than formulae. For the last entry this gives rise to a difference of 0.00000000000005
, ie about twice as much as above, and in some cases as much as 0.00000000000009
, about 78 nanoseconds.
With rounding to the second there are differences of a similar order of magnitude. However, a comparison on the last series fill result, with rounding to the second, with the last result from =MROUND(TIME(0, ROW(1:1)*15,0)+A$2, TIME(0, 0, 1))
using EXACT, returns “TRUE”.
Series fill of an entire column took me about 3 seconds. Then rounding to one second with a formula in another column about 12 seconds.