Solved

Excel 2007 question - using VLOOKUP with Between Date function to return value

Posted on 2011-09-26
8
233 Views
Last Modified: 2012-05-12
I have attached a spreadsheet that shows start and stop dates for certain volume targets (column I) by customer number (column A).  Some records are only one month total, others are many.

I need to take this information and condense it down to ~500 records starting in column M, that shows the customer volume for each month.  so for the first record on row 2, I need a formula that says to vlookup M2, then if the records in A2 through I14,000 has a date between columns F & G, then take the volume amount from column I and display.  Not sure if you can combine a VLOOKUP and a date between function, but that is what I'm trying to accomplish.  Thanks in advance. Book2.xlsx
0
Comment
Question by:carndar
  • 4
  • 3
8 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 36602560
Hello carndar,

I put this formula in L2 copied down to L507 (hide if required or move somewhere else)

=COUNTIF(A:A,M2)

and then this formula in N2 copied across and down to AB507

=LOOKUP(N$1,INDEX($F$2:$F$15000,SUM($L$1:$L1)+1):INDEX($F$2:$F$15000,SUM($L$2:$L2)),INDEX($I$2:$I$15000,SUM($L$1:$L1)+1):INDEX($I$2:$I$15000,SUM($L$2:$L2)))

That could be shortened using OFFSET but the formula would probably be less efficient

Note: I formatted columns F and G as dates - that isn't strictly necessary but it won't affect the formula

see attached

regards, barry
27328856.xlsx
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36604763
...actually....better with VLOOKUP rather than LOOKUP, then it can be shorter, i.e. this formula in N2 copied across and down

=VLOOKUP(N$1,INDEX($F$2:$F$15000,SUM($L$1:$L1)+1):INDEX($I$2:$I$15000,SUM($L$2:$L2)),4)

see revised attachment

I note that there are some #N/A errors further down (because the date ranges for some codes don't start until 2011). If you want the formula can be modified to show zero, e.g. with IFERROR

=IFERROR(VLOOKUP(N$1,INDEX($F$2:$F$15000,SUM($L$1:$L1)+1):INDEX($I$2:$I$15000,SUM($L$2:$L2)),4),0)

barry
27328856v2.xlsx
0
 
LVL 26

Expert Comment

by:redmondb
ID: 36614516
... and please see attached my version -

=SUM($I$2:$I$15000*($A$2:$A$15000=$M2)*(N$1>=$F$2:$F$15000)*(N$1<=$G$2:$G$15000))

Few points...
(1) Barry and I have, I think, differed in our handling of multiple entries matching the criteria. In any event, I have pasted Barry's values (from his first file) starting in column M and highlighted the differences in red.
(2) You mentioned row 14,000 as being the last to check, but there are a number of rows beyond that. Like Barry, I assumed that this was a misprint and used 15,000 instead.
(3) My formulas must be entered as array formulas so use Ctrl+Shift+Enter rather than simply Enter.

Regards,
Brian.

 Book2-V4.xlsx
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 36627716
Hello carndar/Brian,

Well spotted Brian - I picked up the #N/As, of course, which could be fixed with IFERROR as I suggested but there are some other discrepancies that I didn't notice.

Perhaps unwisely I didn't consider that there might be multiple entries matching the criteria.......

My VLOOKUP type approach finds a single value, whereas Brian's summing approach, as he says, will sum column I for all matching rows - the discrepancies come when there are overlapping date ranges - because of the nature of VLOOKUP with a missing 4th argument (equivalent to setting to TRUE) this means that the second entry is taken when there are two matches, e.g. for rows 6968 and 6969 where the date ranges overlap my suggestion takes the second entry which is zero. I assume that summing works in this case because it appears that there is always one entry with a zero and one non-zero, perhaps that wouldn't be legitimate if there were two equal non-zero values?

For the same results as Brian SUMIFS should be considerably more efficient in Excel 2007, i.e. with this formula

=SUMIFS($I$2:$I$15000,$A$2:$A$15000,$M2,$F$2:$F$15000,"<="&N$1,$G$2:$G$15000,">="&N$1)

regards, barry
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 26

Expert Comment

by:redmondb
ID: 36634258
carndar,

The FormulaMeister's "SumIfs" is definitely the way to go - my "Sum" is an absolute dog (coming from an old dog, perhaps?).

Nice one Barry!

Regards,
Brian.
0
 

Author Closing Comment

by:carndar
ID: 36700511
You guys are incredible!  Thanks for the quick response!
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 36709415
Thanks for the comments carndar - it might be that SUMIFS was the best solution for you but please can you consider re-allocating the points here - I wouldn't have arrived at that solution without Brian's work - that was just a more efficient version of the formula Brian had already proposed - so a points split here would be more equitable I think

regards, barry
0
 
LVL 26

Expert Comment

by:redmondb
ID: 36710052
Barry,

I appreciate your kind offer more than any points. I'm happy for things to be left as they are.

Swings and roundabouts!

Regards,
Brian.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now