Search code examples
arraysgoogle-sheetsgoogle-sheets-formulaarray-formulasgs-vlookup

How to pull the first value after a date from one tab into another in google sheets?


I have a tab in google sheets with a weekly stock price data (columns are date and price). I have another tab with some signals (date and long entry price).

I want to add a column to the first sheet (long entry) that pulls in the first long entry price from the signals tab into the rows after (and between) the signal date and the close date.

For example, in prices, I have:

date       | price
2006-01-01 | 30.00
2006-01-07 | 31.00
2006-01-14 | 32.00
2006-01-21 | 33.00
2006-01-28 | 34.00

In signals, I have:

date       | entry_price
2006-01-03 | 33.30
2006-01-12 | 32.10

I want:

date       | price | entry_price
2006-01-01 | 30.00 | 
2006-01-07 | 31.00 | 33.30
2006-01-14 | 32.00 | 32.10
2006-01-21 | 33.00 | 32.10
2006-01-28 | 34.00 | 32.10

See how it has no entry price for 1/1/2006? Thats because there is no signal before 1/3. And see how the entry price from the 1/12 signal is used for 1/14, 1/21/ and 1/28? Thats because thats the first date after the last signal.

Here's a google sheet that has this stuff in it.

I'm hoping there's a simple way to do what i want using vlookup, query, etc but I don't know what it is :)

Thanks!


Solution

  • use:

    =ARRAYFORMULA(IFNA(VLOOKUP(A2:A, signals!A:B, 2, 1)))
    

    0