I'm trying to display multiple stocks in a single table. I have the following formula For A2:
=QUERY(GOOGLEFINANCE(B1, "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "DAILY"), "offset 1", 0)
And the following formula for C2:
=QUERY(GOOGLEFINANCE(C1, "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "DAILY"), "select Col2 offset 1", 0)
What I want to do is have the data end on the same row. The issue is that not all stocks have the same number of data points as some are younger than others. For this example, MUTF:DOXGX oldest start date is May 6, 2022; approximately 34 months ago.
Here is how the table generates, where "..." is a skip in rows:
Date | MUTF:SVSPX | MUTF:DOXGX |
---|---|---|
3/28/2022 | 261.27 | 229.42 |
3/29/2022 | 264.47 | 231.33 |
... | ... | ... |
5/6/2022 | 235.66 | 222.63 |
... | ... | ... |
2/19/2025 | 269.2 | 270.63 |
2/20/2025 | 268.07 | 265.5 |
2/21/2025 | 263.5 | |
2/24/2025 | 262.2 | |
... | ... | |
3/24/2025 | 252.27 | |
3/26/2025 | 249.86 |
I'm trying to display multiple stocks in a single table. I have the following formula For A2:
=QUERY(GOOGLEFINANCE(B1, "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "DAILY"), "offset 1", 0)
And the following formula for C2:
=QUERY(GOOGLEFINANCE(C1, "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "DAILY"), "select Col2 offset 1", 0)
What I want to do is have the data end on the same row. The issue is that not all stocks have the same number of data points as some are younger than others. For this example, MUTF:DOXGX oldest start date is May 6, 2022; approximately 34 months ago.
Here is how the table generates, where "..." is a skip in rows:
Date | MUTF:SVSPX | MUTF:DOXGX |
---|---|---|
3/28/2022 | 261.27 | 229.42 |
3/29/2022 | 264.47 | 231.33 |
... | ... | ... |
5/6/2022 | 235.66 | 222.63 |
... | ... | ... |
2/19/2025 | 269.2 | 270.63 |
2/20/2025 | 268.07 | 265.5 |
2/21/2025 | 263.5 | |
2/24/2025 | 262.2 | |
... | ... | |
3/24/2025 | 252.27 | |
3/26/2025 | 249.86 |
As you can see, it shows that the MUTF:DOXGX stock ends on 2/20/2025, but that isn't true.
What I want to have instead is that the values for MUTF:DOXGX starts on its oldest date, which would be 5/6/2022. I figure that how this would work would be to take the difference between the last row of each column using =MAX(FILTER(ROW(C3:C), C3:C <> "")) - MAX(FILTER(ROW(B3:B), B3:B <> ""))
then somehow using that returned value to tell the QUERY
formula to just move the data down that many rows?
Edit: As per the suggestion of @leylou, here is my input values:
Date | MUTF:SVSPX | MUTF:DOXGX |
---|---|---|
=QUERY(GOOGLEFINANCE("MUTF:SVSPX", "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "WEEKLY"), "offset 1", 0) | =QUERY(GOOGLEFINANCE("MUTF:DOXGX", "close", EDATE(TODAY(), -LEFT("36 Months", FIND(" ", "36 Months"))), TODAY(), "WEEKLY"), "select Col2 offset 1", 0) |
Here is my desired output:
Date | MUTF:SVSPX | MUTF:DOXGX |
---|---|---|
3/25/2022 | 259.41 | |
4/1/2022 | 259.61 | |
4/8/2022 | 256.39 | |
4/14/2022 | 250.96 | |
4/22/2022 | 244.08 | |
4/29/2022 | 236.09 | |
5/6/2022 | 235.66 | 230.43 |
5/13/2022 | 230.1 | 226.36 |
5/20/2022 | 223.19 | 223.37 |
5/27/2022 | 237.99 | 238.92 |
6/3/2022 | 235.24 | 235.33 |
6/10/2022 | 223.39 | 222.63 |
6/17/2022 | 210.55 | 210.75 |
6/24/2022 | 223.27 | 221.55 |
7/1/2022 | 218.38 | 216.27 |
7/8/2022 | 222.69 | 217.53 |
7/15/2022 | 220.66 | 215.11 |
7/22/2022 | 226.33 | 219.97 |
7/29/2022 | 236.03 | 225.26 |
8/5/2022 | 236.93 | 225.45 |
8/12/2022 | 244.77 | 234.65 |
8/19/2022 | 241.91 | 231.74 |
8/26/2022 | 232.15 | 224.18 |
9/2/2022 | 224.62 | 217.69 |
9/9/2022 | 232.89 | 224.37 |
9/16/2022 | 221.85 | 214.85 |
9/23/2022 | 210.72 | 201.95 |
9/30/2022 | 204.63 | 198.06 |
10/7/2022 | 207.84 | 205 |
10/14/2022 | 204.6 | 202.86 |
10/21/2022 | 214.31 | 211.41 |
10/28/2022 | 222.83 | 221.85 |
11/4/2022 | 215.45 | 219.04 |
11/11/2022 | 228.23 | 229.14 |
11/18/2022 | 226.81 | 227.22 |
11/25/2022 | 230.34 | 231.53 |
12/2/2022 | 233.08 | 234.2 |
12/9/2022 | 225.26 | 225.87 |
12/16/2022 | 220.63 | 221.11 |
12/23/2022 | 201.42 | 215.05 |
12/30/2022 | 201.21 | 215.73 |
1/6/2023 | 204.18 | 220.9 |
1/13/2023 | 209.71 | 225.59 |
1/20/2023 | 208.35 | 223.87 |
1/27/2023 | 213.51 | 229.05 |
2/3/2023 | 217.02 | 230.92 |
2/10/2023 | 214.69 | 230.06 |
2/17/2023 | 214.27 | 229.44 |
2/24/2023 | 208.57 | 223.66 |
3/3/2023 | 212.64 | 225.92 |
3/10/2023 | 202.98 | 212.17 |
3/17/2023 | 206 | 209.04 |
3/24/2023 | 208.1 | 210.75 |
3/31/2023 | 215.42 | 216.47 |
4/6/2023 | 215.27 | 216.94 |
4/14/2023 | 217.02 | 219.89 |
4/21/2023 | 216.83 | 218.77 |
4/28/2023 | 218.75 | 218.98 |
5/5/2023 | 217.04 | 215.41 |
5/12/2023 | 216.5 | 212.58 |
5/19/2023 | 220.2 | 217.68 |
5/26/2023 | 220.97 | 216.67 |
6/2/2023 | 225.13 | 220.38 |
6/9/2023 | 226.04 | 222.06 |
6/16/2023 | 231.98 | 226.5 |
6/23/2023 | 227.94 | 222.17 |
6/30/2023 | 233.33 | 227.44 |
7/7/2023 | 230.73 | 225.7 |
7/14/2023 | 236.35 | 231.02 |
7/21/2023 | 238 | 236.63 |
7/28/2023 | 240.47 | 237.7 |
8/4/2023 | 235.04 | 234.92 |
8/11/2023 | 234.38 | 236.4 |
8/18/2023 | 229.55 | 229.41 |
8/25/2023 | 231.51 | 229.22 |
9/1/2023 | 237.4 | 234.31 |
9/8/2023 | 234.39 | 232.27 |
9/15/2023 | 234.1 | 234.34 |
9/22/2023 | 226.44 | 228.17 |
9/29/2023 | 224.82 | 226.31 |
10/6/2023 | 225.97 | 223.31 |
10/13/2023 | 227 | 225.13 |
10/20/2023 | 221.59 | 220.11 |
10/27/2023 | 215.99 | 213.65 |
11/3/2023 | 228.69 | 226.44 |
11/10/2023 | 231.76 | 225.39 |
11/17/2023 | 237.12 | 230.91 |
11/24/2023 | 239.54 | 233.14 |
12/1/2023 | 241.54 | 237.14 |
12/8/2023 | 242.11 | 237.74 |
12/15/2023 | 248.24 | 245.66 |
12/22/2023 | 224.66 | 242.51 |
12/29/2023 | 225.43 | 243.56 |
1/5/2024 | 222.03 | 243.62 |
1/12/2024 | 226.18 | 244.33 |
1/19/2024 | 228.87 | 243.3 |
1/26/2024 | 231.3 | 246.86 |
2/2/2024 | 234.55 | 245.07 |
2/9/2024 | 237.81 | 245.82 |
2/16/2024 | 236.98 | 247.18 |
2/23/2024 | 240.94 | 250.75 |
3/1/2024 | 243.33 | 250.79 |
3/8/2024 | 242.77 | 253.94 |
3/15/2024 | 242.54 | 254.62 |
3/22/2024 | 247.42 | 260.35 |
3/28/2024 | 248.4 | 258.05 |
4/5/2024 | 246.08 | 255.26 |
4/12/2024 | 242.32 | 249.63 |
4/19/2024 | 234.95 | 248.83 |
4/26/2024 | 241.25 | 252.47 |
5/3/2024 | 242.6 | 251.04 |
5/10/2024 | 247.2 | 257.2 |
5/17/2024 | 251.15 | 259.54 |
5/24/2024 | 251.26 | 256.3 |
5/31/2024 | 250.01 | 257.78 |
6/7/2024 | 253.4 | 256.35 |
6/14/2024 | 257.5 | 253.43 |
6/21/2024 | 259.11 | 257.36 |
6/28/2024 | 258.12 | 256.87 |
7/5/2024 | 263.21 | 257.17 |
7/12/2024 | 265.55 | 262.15 |
7/19/2024 | 260.36 | 261.76 |
7/26/2024 | 258.2 | 266.45 |
8/2/2024 | 252.89 | 260.45 |
8/9/2024 | 252.83 | 260.12 |
8/16/2024 | 262.92 | 266.11 |
8/23/2024 | 266.77 | 270.09 |
8/30/2024 | 267.5 | 273.54 |
9/6/2024 | 256.19 | 264.08 |
9/13/2024 | 266.59 | 268.95 |
9/20/2024 | 270.29 | 272.39 |
9/27/2024 | 271.2 | 273.3 |
10/4/2024 | 271.91 | 273.9 |
10/11/2024 | 274.98 | 277.08 |
10/18/2024 | 277.37 | 279.44 |
10/25/2024 | 274.69 | 275.68 |
11/1/2024 | 270.96 | 274.89 |
11/8/2024 | 283.67 | 284.85 |
11/15/2024 | 277.85 | 280.76 |
11/22/2024 | 282.63 | 285.27 |
11/29/2024 | 285.67 | 288.05 |
12/6/2024 | 288.49 | 283.96 |
12/13/2024 | 286.73 | 277.67 |
12/20/2024 | 281.08 | 257.68 |
12/27/2024 | 261.22 | 259.43 |
1/3/2025 | 260.02 | 259.3 |
1/10/2025 | 255.03 | 255.98 |
1/17/2025 | 262.5 | 266.72 |
1/24/2025 | 267.12 | 272.48 |
1/31/2025 | 264.47 | 273.04 |
2/7/2025 | 263.85 | 271.91 |
2/14/2025 | 267.86 | 274.64 |
2/21/2025 | 263.5 | 272.47 |
2/28/2025 | 260.98 | 275.27 |
3/6/2025 | 251.55 | 270.27 |
3/14/2025 | 247.31 | 265.29 |
3/17/2025 | 248.92 | 267.26 |
- Please provide sample input data and desired output. You may create one with the help of this link. – leylou Commented Mar 27 at 17:36
- What you can do here is to list all of the dates from 3 years ago up to today and then use a BYROW and VLOOKUP to search for the values for the corresponding dates. However, this would consume 1098 rows. We can add a filter afterwards to remove the rows with no data. – PatrickdC Commented Mar 27 at 18:03
1 Answer
Reset to default 2You may try this and place it on A2 (as this formula already generates all columns including the dates):
=LET(dates, ARRAYFORMULA(TO_DATE(SEQUENCE((365*3)+1,1,TODAY()-(365*3)-1 + (16/24),1))),
svspx, GOOGLEFINANCE(B1, "close", EDATE(TODAY(), -36), TODAY(), "DAILY"),
svspxdata, IFERROR(BYROW(TOCOL(dates,1), LAMBDA(x, VLOOKUP(x,svspx,2,0)))),
doxgx, GOOGLEFINANCE(C1, "close", EDATE(TODAY(), -36), TODAY(), "DAILY"),
doxgxdata, IFERROR(BYROW(TOCOL(dates,1), LAMBDA(x, VLOOKUP(x,doxgx,2,0)))),
QUERY(HSTACK(dates,svspxdata, doxgxdata),"SELECT * WHERE Col2 IS NOT NULL"))
given that B1
is MUTF:SVSPX
and C1
is MUTF:DOXGX
. I do not wish to add the output as my output produced 744 rows (not unless that is an issue to others).
NOTE: Changing the "DAILY"
input to "WEEKLY"
produces 154 rows.