I've a regularly updating sheet of daily foreign exchange rates (descending order sorted).
I've written a cell formula, which works fine if I drag it to the end.
=IFNA( VLOOKUP(A2,USD_TRY!$A$2:$B$3289,2,FALSE), INDEX(USD_TRY!$A$2:$C$3289, MATCH(A2,USD_TRY!$A$2:$A$3289,-1), 3 ) )
Column A2:A
is daily dates, merged from 2 different sheets of daily rates and different currencies (so it skips some dates) but it has more dates than the column USD_TRY!A2:A
. This formula gets the Price
rate from column USD_TRY!B2:B
if the VLOOKUP()
date matches but if it doesn't match then it gets the Open
rate from column USD_TRY!C2:C
a row before (a day after) the closest match. However, if I convert the same formula to ARRAYFORMULA()
then the VLOOKUP()
part works fine but the INDEX(MATCH())
part gives a wrong result of USD_TRY!C2
every time.
IF(
AND(NOT(ISBLANK(A2:A)), NOT(ISBLANK('USD_TRY Historical Data'!A2:A)), NOT(ISBLANK('USD_TRY Historical Data'!B2:B)), NOT(ISBLANK('USD_TRY Historical Data'!C2:C)) ),
ARRAYFORMULA(
IFNA(
VLOOKUP(A2:A,'USD_TRY Historical Data'!A2:B,2,FALSE),
INDEX('USD_TRY Historical Data'!A2:C, MATCH(A2:A,'USD_TRY Historical Data'!A2:A,-1), 3 ) )
)
)
}
How do I correct the ARRAYFORMULA()
and is there any simpler way to get the correct results as array?
Source data:
Correct output (with cell formula):
Wrong result (with array formula):
CodePudding user response:
try:
=ARRAYFORMULA(IFNA(
VLOOKUP(A2:A4, E2:F6, 2, 0),
VLOOKUP(90000-A2:A4, {90000-E2:E6, G2:G6}, 2, 1)))