Phil
asked on
Want to find an Excel formula to lookup the value to the right of the next smallest date
I'm trying to create a formula similar to a vlookup that finds the next smallest occurance of a date and selects the value in the column to the right of the date found. I have attached an excel spreadsheet example to help explain. I'm using Excel 2010 with Windows 7.
Thanks!
Phil
Excel-Lookup-Example.xlsm
Thanks!
Phil
Excel-Lookup-Example.xlsm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Brad,
Sorry, I didn't see that you had commented before I accepted Kevin's suggestion.
Your formula works also. Is there any way I can give you points for this as well?
Thanks so much...
Phil
Sorry, I didn't see that you had commented before I accepted Kevin's suggestion.
Your formula works also. Is there any way I can give you points for this as well?
Thanks so much...
Phil
Phil,
While the two formulas return the same result if you paste them in one cell only, they give different results if you copy them down a long column of data. Kevin's formula always returns the same answer. Mine will return a different answer depending on the date in column B.
Which behavior do you need? If the formula will only be applied in one cell, then Kevin posted first and deserves all the points. But if you do need different answers depending on the date in column B, then a split would be appropriate. I'd be glad to reopen the question in such a situation.
Brad
While the two formulas return the same result if you paste them in one cell only, they give different results if you copy them down a long column of data. Kevin's formula always returns the same answer. Mine will return a different answer depending on the date in column B.
Which behavior do you need? If the formula will only be applied in one cell, then Kevin posted first and deserves all the points. But if you do need different answers depending on the date in column B, then a split would be appropriate. I'd be glad to reopen the question in such a situation.
Brad
ASKER
Hi Brad,
I attached a copy of the actual spreadsheet involving this formula. It starts in range("AE3") and copied down to the last row. The formula is a modified version of Kevin's formula which yours may be able to replace. I have had some circular reference issues and also Excel has crashed a few times when I had too many records and tried to delete them.
This spreadsheet is a sheet used to backtest a daytrading system that I created. The system trades a maximum of three symbols per day and the number of shares is calculated with the formula in question (selecting the previous days portfolio balance, dividing by the number of maximum trades, and then dividing by the trigger price per share).
I will try your formula and see how it works. If you have any questions, please let me know.
Thanks so much, Phil
I attached a copy of the actual spreadsheet involving this formula. It starts in range("AE3") and copied down to the last row. The formula is a modified version of Kevin's formula which yours may be able to replace. I have had some circular reference issues and also Excel has crashed a few times when I had too many records and tried to delete them.
This spreadsheet is a sheet used to backtest a daytrading system that I created. The system trades a maximum of three symbols per day and the number of shares is calculated with the formula in question (selecting the previous days portfolio balance, dividing by the number of maximum trades, and then dividing by the trigger price per share).
I will try your formula and see how it works. If you have any questions, please let me know.
Thanks so much, Phil
ASKER
Sorry, I think I forgot to actually attach the file.
PBDT-Test-20120331g.zip
PBDT-Test-20120331g.zip
Phil,
Because your dates in column AO are already sorted in ascending order, there is no need to take the MAX of an ever-growing range. You can therefore simplify the formula in cell AE3 to either of:
=IF(AD3>0,ROUND(VLOOKUP(AO 3-1,AO:AP, 2)/AJ$1/AD 3,0),0) 'TRUE is the default value of fourth parameter in VLOOKUP
=IF(AD3>0,ROUND(VLOOKUP(AO 3-1,AO:AP, 2,TRUE)/AJ $1/AD3,0), 0)
I tested column AO to make sure that it was arranged in ascending order--it is. I also tested the suggested formula to make sure it returned the same answer as what you are using--it does.
Brad
Because your dates in column AO are already sorted in ascending order, there is no need to take the MAX of an ever-growing range. You can therefore simplify the formula in cell AE3 to either of:
=IF(AD3>0,ROUND(VLOOKUP(AO
=IF(AD3>0,ROUND(VLOOKUP(AO
I tested column AO to make sure that it was arranged in ascending order--it is. I also tested the suggested formula to make sure it returned the same answer as what you are using--it does.
Brad
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A special thanks to you Brad for your expert clarifications and extra effort!
ASKER
Multiple possibilities and they all work. Thanks so much!
Phil
Phil
ASKER