Add 2 sparlines in a google sheet to create a new sparkline - google-sheets

I have 2 sparklines. Both are created based on historical share prices of stocks from a year ago to today.
I want to create a new sparkline that is the sum of these 2 charts. Is this possible given that the have the same number of data points i.e 365.
e.g
=SPARKLINE(GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),{"charttype","line";"linewidth",1;"color","#5f88cc"})
=SPARKLINE(GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily"),{"charttype","line";"linewidth",1;"color","#5f88cc"})

You can join them as a single array and then use query to add them:
=SPARKLINE(
QUERY(
{
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
},
"select Col1, Col2+Col4",
1
)
)
Rundown
We first join the two arrays. To do so we use the array syntax {A,B} to join them row by row, making a 4 column array:
={
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
}
Now we can apply a query to get the values we want:
=QUERY(
{
GOOGLEFINANCE("AMZN","price",TODAY()-365,TODAY(),"daily"),
GOOGLEFINANCE("MSFT","price",TODAY()-365,TODAY(),"daily")
},
"select Col1, Col2+Col4",
1
)
The query is making 2 rows:
The date column. Since it should be the same for both, no need to change anything
The sum of the 2 Close columns (2 and 4)
After that we can simply wrap everything to the SPARKLINE function, and we have our final result.
If you don't like having the whitespace characters, you can remove them without any problem.
Reference
Using arrays in Google Sheets (Google Docs Editors Help)
QUERY function (Google Docs Editors Help)

Related

How to use Arrayformula on some of the rows in two ranges

I'm trying to make some protected sheet which will combine data from two others:
Sheet1 - Has mix of entries:
Sheet2 - Has only t1 entries
Sheet3 (protected) - Need ARRAYFORMULA for this sheet to be able to make following:
So in Sheet3 I need to take all t1 entries from Sheet1 and all entries from Sheet2 and list them in Sheet3 ordered by Date.
But so far I could do only ARRAYFORMULA(Sheet1!A2:C5) which copies all entries from Sheet1
This is a job for QUERY formula:
Try this in Sheet3:
=query({Sheet1!A1:C;Sheet2!A1:C},"select * where Col1='t1' order by Col3 asc",1)
Find working example here: https://docs.google.com/spreadsheets/d/1P6uYZcQJqKt7OVPhYtMoDkssfFbhsJVSGACI8u9qMmo/copy
First:
I combine 2 ranges using { } notation
{range1;range2} means that I stack 2 ranges - one on another.
Then using QUERY i select all the Columns in my combined range and order them by third column.
Number 1 at the end of the formula means that range has one row of headers.
=sort({filter(Sheet1!A2:C5,Sheet1!A2:A5="t1");filter(Sheet2!A2:C5,Sheet2!A2:A5="t1")},3,true)
works.
For larger sheets, you should be able to drop the numeral 5 in the above formula.
The {} bracket means local array. ; means vertical concatenation. For sort() and filter(), see official documentation.

Combing base data set for a formula from two *other* Google sheets

We have hit the dreaded 5 million rows limit which is so small for any semi-serious data.
We have an important ArrayFormula piece in one of our worksheets (tab) currently that summarizes the data from another worksheet in the same file where time series data is kept with dates. This is our current function:
=ArrayFormula(SUMIFS(DataSheet!$B:$B,
MONTH(DataSheet!$A:$A), 1,
YEAR(DataSheet!$A:$A), 2020)
)
Explanation: This basically summed all of column B in the DataSheet tab for the month of Jan 2020 based on date found in column A of that sheet.
However, this worksheet of data that is now running close to that row limit. We can move it to another Google Sheets file, and refer to the same data via IMPORTRANGE.
The question then is how to refer to that data instead of the DataSheet!$A:$A in the above old formula? Will this reference be replaced by the entire IMPORTRANGE function?
Old:
=ArrayFormula(SUMIFS(DataSheet!$B:$B,
MONTH(DataSheet!$A:$A), 1,
YEAR(DataSheet!$A:$A), 2020)
)
New:
=ArrayFormula(SUMIFS(IMPORTRANGE(filename, rows)!$B:$B,
MONTH(IMPORTRANGE(filename, rows)!$A:$A, 1,
YEAR(IMPORTRANGE(filename, rows)!$A:$A, 2020)
)
This does not work of course, because we cannot have the exclamation ! followed by the column in an importrange. Any other thoughts?
Try this in cell A1 on a fresh, brand new tab somewhere:
=ARRAYFORMULA(QUERY(1*TEXT(IMPORTRANGE("[spreadsheet key]","Sheet1!A:B"),{"mmmyyyy","0.00"}),"select Col1,SUM(Col2) where Col2<>0 group by Col1 order by Col1")
The "spreadsheet key" is the combination of letters and numbers after the "/d/" and before the "/edit..." in the URL of your source sheet.
Obviously, you'd also replace "Sheet1!A:B" with whatever the real tab/column reference is.
Then, select all of Column A and from the Menu choose Format>Number>More Formats>Custom Number Formatting, Then this in the dialog box:
mmmm yyyy
You want to IMPORTRANGE from two different sheets in a different spreadsheet.
While the following formula will import data from both sheets, it will also import the blank rows, so you might have to scroll down hundreds of rows in order to see the data from the second sheet (and this might give your the wrong impression that the second sheet is not getting imported):
{
IMPORTRANGE("SPREADSHEET_ID","CurrentMonth!$A:$J");
IMPORTRANGE("SPREADSHEET_ID","All2020!$A:$J")
}
You can use QUERY in order to filter out blank rows:
=QUERY(
{
IMPORTRANGE("SPREADSHEET_ID","CurrentMonth!$A:$J");
IMPORTRANGE("SPREADSHEET_ID","All2020!$A:$J")
},
"SELECT * WHERE Col1 IS NOT NULL ORDER BY Col1 DESC"
)
Note:
I thought you'd like to sort the data according to the date in column A, please remove ORDER BY Col1 DESC if that's not the case.

How do I create a multiple sheets that use a google sheet named TOTAL as the data source?

How do I create multiple sheets that use a Google sheet named TOTAL as the data source? Each sheet must contain the same three columns from TOTAL and other specific data, for instance, FLUX will have six columns, three from TOTAL and three custom columns added manually.
I used a query function to import the data from TOTAL to FLUX so that updating data in TOTAL will update it also in FLUX
The data in TOTAL are not fixed. It will change adding rows, which might change the order of the list. For instance, adding the row 13 in TOTAL will shift down the data in column A:C in FLUX, but not columns D:F
Is that a way to keep the reference out of the QUERY part?
Here an example: Click me
you would need to create ID system and then you would be able to match your query with rest of the static columns. in sheet SALES remove that query and put IDs in A column. then your query will be:
=QUERY(TOTAL!A1:D, "SELECT A, B, C, D WHERE C is not null", 1)
where column A contains IDs and then you create new sheet SHEET3 and paste this query in A1
and this formula in E1:
=ARRAYFORMULA(IFERROR(VLOOKUP(A1:A, SALES!A1:G, {4,5,6}, 0), ))
I have the same problem and I can't understand few steps from the answer.
Firstly, the A columns of both sheets (TOTAL and SALES) must have IDs?
Secondly, I can't really understand how the Sheets SALES should look like. Should it be like, Col A = IDs, ColB to C query from TOTAL and Col E to G static data?
In this case is it still correct creating a query in Sheet3 reading data from TOTAL?
Thank

Combining multiple spreadsheets in one using IMPORTRANGE

I would like to aggregate the data of multiple spreadsheets into one spreadsheet.
Spreadsheet 1 has a Row of Strings A2:A500
Spreadsheet 2 has a Row of Strings A2:A500
Spreadsheet 3 is supposed to have a Row of both (Spreadsheet1!A2:A500 AND Spreadsheet2!A2:A500).
Duplicates shall not be handled differently. I would like them to appear as often as they appear in the different sheets.
Is it possible to do this without writing a script or using jQuery, e.g. by using IMPORTRANGE?
What does not work: I have tried using IMPORTRANGE as follows:
ARRAY{IMPORTRANGE("key-of-spreadsheet1","list!A2:A500"), IMPORTRANGE("key-of-spreadsheet2", "list!A2:A500")}
This causes an error.
You should be able to use a vertical array in the Spreadsheet 3:
={IMPORTRANGE("Sheet1Key","SheetName!A2:A500");IMPORTRANGE("Sheet2Key","SheetName!A2:A500")}
Of course, it is also possible to combine several IMPORTRANGE() functions with the QUERY() function, which gives us a greater control over the results we import.
For example, we can use such a construction:
=QUERY(
{
IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-2", "'sheet-name-2'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-3", "'sheet-name-3'!A2:Z100");
IMPORTRANGE("key-or-url-of-spreadsheet-4", "'sheet-name-4'!A2:Z100")
},
"SELECT * WHERE Col1 IS NOT NULL ORDER BY Col3 ASC"
)
###Explanation:
The above query removes blank lines from imported ranges:
SELECT * WHERE Col1 IS NOT NULL
and sorts ascending all data collected together in relation to the third column:
ORDER BY Col3 ASC
For descending, just use DESC in place of ASC.
Of course, we can also arrange any other criteria, or omit them displaying everything without modification:
"SELECT * "
###Note:
In order to use the above constructed query, we first need to call a single IMPORTRANGE() method for each of the spreadsheets we want to refer:
=IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100")
We have to do this even if we refer to the same spreadsheet in which we write this formula, but for every spreadsheet it is enough to do it once.
This is to be able to connect these sheets and allow access to the sheets (to which we have the access rights anyway):
                                                    
After giving permission for all spreadsheets, we can use the above query.
I am also applying above given formula for getting data from multiple spreadsheet which is getting an error something is like IN ARRAY_LITERAL An array literal was missing values for one or more rows.
Easy fix: Apply the filter to the entire column / sheet instead of just the current selection. This will automatically update all of the filters to include new additions.

Merging data in google sheets from multiple sheets with varying number of rows

I have multiple google sheets with each containing variable number of rows but fixed set of columns. The number of rows can change in any sheet with time. How can i create summary sheet with data from all sheets placed one after the other? eg. If sheet 1 has 5 rows and sheet 2 has 6, i want the summary sheet to have 11 rows with 1-5 containing data from sheet 1 and 6-11 data from sheet 2.
= {
FILTER(NamedRange1, NamedRange1Col1 <> '');
Filter(NamedRange2, NamedRange1Col1 <> '')
}
Please create a named range for each sheet. This ranges will comntain your data.
Within each named range, also create a named range column. This can be the first column of every named range, or any column.
We are using the filter function FILTER so that you do not import empty rows. You dont have to use it though. The curly braces are semicolon are the crucial parts. In general, you "stack" multiple arrays as follows:
= {Array1; Array2;...;Array n}
the correct syntax is:
={FILTER(Sheet1!A:C; Sheet1!B:B<>"");
FILTER(Sheet2!A:C; Sheet2!B:B<>"")}
and another solution would be:
=QUERY({Sheet1!A:C; Sheet2!A:C}; "where Col2 is not null", 0)

Resources