How to join rows and cols in google spread sheets - google-sheets

Here are 4 cells like this.
A B
1 a b
2 c d
I want to join them by , and ¥n.
C1 => a,b¥nc,d
How can I do this with functions google spread sheets have and without javascript? https://support.google.com/docs/table/25273?hl=en

See if something like this works:
=ArrayFormula(Substitute(JOIN("¥n", query(trim(transpose(A1:B2)),,rows(A1:A2)))," ", ", "))
The query() creates an output of two cells where the values of each row are joined, separated with a space. (note the use of the optional headers argument, set to the number of rows.
Then these two cells are joined with "¥n".
Finally the spaces are substituted with a comma.

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.

How to create arrayformula sequence number separated by comma in google sheets

How to create arrayformula sequence number separated by comma in google spreadsheets
expected results is in column B
A
B
5
1,2,3,4,5
2
1,2
3
1,2,3
How about the following sample formula?
Sample formula:
=JOIN(",",ARRAYFORMULA(ROW(INDIRECT("A1:A"&A1))))
When you use this formula, please put this to a cell "B1" and drag down it.
The flow of this formula is as follows.
Create a1Notation of cells using "A1:A"&A1 using INDIRECT.
Retrieve row numbers from the a1Notation using ROW.
Join the row numbers with , using JOIN.
Result:
Note:
When you want to put all result values using one formula, unfortunately, I couldn't find the formula using the built-in functions. In that case, I would like to propose to a custom function as follows. When you use this, please copy and paste the following script to the script editor of Spreadsheet.
And, please put a formula of =SAMPLE(A1:A) to a cell "B1". By this, the result values are put to the column "B" using the values of column "A".
const SAMPLE = v => v.map(([e]) => e && !isNaN(e) ? [...Array(e)].map((_, i) => i + 1).join(",") : "");
References:
INDIRECT
ROW
JOIN
Custom Functions in Google Sheets
You can use TEXTJOIN() with SEQUENCE() function.
=TEXTJOIN(",",TRUE,SEQUENCE(A1))
You can also use this functions in desktop Excel365

Dynamic query formula nested inside an array

I have a query formula in Google sheets that updates based on additional columns of data in my Google Sheet seen here =QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",)
So it may add QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)and then it will end up becoming the below and so on for each additional.
=QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)
What I am trying to do is have the resultant query formula which is in cell 'List'!A1 as QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",) be used in an array formula as a reference so I don't have to update the formula each time a new query formula is added.
The static query formula is
=SORT(ARRAYFORMULA({QUERY('Deals List - URL Split'!A:DZ, "select A, C where C contains 'http'",);QUERY('Deals List - URL Split'!A:DZ, "select A, E where E contains 'http'",)}),1,TRUE,2,TRUE)
and indeally the one that gets the dynamic formula would be like below but I always get an error and get just the literal static formula above.
=SORT(ARRAYFORMULA({'List'!A1}),1,TRUE,2,TRUE)
I think I have an answer (or two) for you. After looking at your sheet, I have to say that I am sure that a simpler design is possible for your sheets, that would simplify everything. Anyway, I've built one formula, using only your data on sheet '2 URL SPLIT'!, and the desired columns from '4 URL FILTER'!A1:1. See my sample tab, GK-6 ITEMS AND URLS, added to your sheet.
The formula, reduced to its basic form, is:
={
IFERROR({'2 URL SPLIT'!$A$2:$A, INDIRECT(INDEX(
{ARRAYFORMULA(IFERROR("'2 URL SPLIT'!"
& TRANSPOSE('4 URL FILTER'!1:1)
& TRANSPOSE(SPLIT(
{"2:"
& TEXTJOIN("~2:",1,TRANSPOSE('4 URL FILTER'!1:1))},"~",0,0))
& ROWS('2 URL SPLIT'!A:A)))},1,0))},{"",""})
}
The formula is not truly dynamic, but it ignores blank columns. So the cheat I've used is to expand the capacity of the formula to include extra blank columns, and if they get filled with data, the data will be used. I've set it to include 50 columns of data, where you are currently using 39, but you could expand it to handle about 200 columns, before it reaches the 50,000 character limit of a cell.
The formula as shown above handles one column. For the one that handles fifty columns, as in my sample sheet, I simply duplicate the inner formula, everything inside the outer braces "{....}" and increment the number in it. You only need to do this once, or copy mine from my sheet. You do not need to update if/when your data columns expand.
I'm happy to add much more explanation if you decide that this formula works for you. But the basis of the formula is dynamically building the ranges of cells to query. The result of this inner part of the formula is shown below. Note that the 2 in each range is hard-coded, and can be changed if your structure changes, but the limit of the range is calculated from your data.
The rest of the formula uses an index into this "table", incrementing by one to select each successive data range, which adds a new column of data to be queried. These data ranges from '2 URL SPLIT!' include column A and one subsequent data column, as specified in '4 URL FILTER'!A1:A, and are stacked one above the other, by using a ";" separator.
The query is then run against this vertical, two column stack, selecting all rows where column 2 contains "http".
The final result is shown below:

Extract unique values from a table in Google Sheet

I'm working on Google Sheet spreadsheets and I'm looking to get in a column the unique values of the table I show.
Suppose the table has the following values
A-B-C
B-C
A-D
With the Split function I can separate the values.
=SPLIT(B12;"-")
A B C
B C
A D
I'm stuck on the final point, which is to get the unique values.
A
B
C
D
In a single formula (sorted, no blanks):
=sort(unique(transpose(split(textjoin("-",1,A:A),"-"))))
Assuming your data is in columns A:C, =UNIQUE({A1:A3;B1:B3;C1:C3}).
You can also unbind the ranges. =UNIQUE({A:A;B:B;C:C}).
The curly braces {} combine the ranges.
The semi colons ; tell the curly braces to combine the ranges vertically into a single column for the UNIQUE function to parse.

How format a result using VLOOKUP to loop inside a single cell with an arbitrary number of search keys

I have a column called "Notes (Atomic weights)" with an arbitrary (0 to n) number of search keys in it.
and a corresponding Named Range called "NOTES"
How do I do a vlookup/Query or Filter such that I get the combined column called "Note Texts" (see image below)?
If there is only one search key in the Notes column, I can use
IF(LEN(W3)>0, VLOOKUP(W3, NOTES, 2, false) , )
but now I have an arbitrary number of search keys in one column. how do I approach this without splitting and creating even more cells and then stitch them all back (adding more columns is very messy, since many other columns in my table also require the same fix).
Try this formula:
=TRANSPOSE(SPLIT(JOIN(char(10),ArrayFormula(IFERROR(VLOOKUP("["&SPLIT(JOIN("! ",A1:A4),"![",1),D1:E3,2,0),"!"))),char(10)&"!"&char(10),0))
Sample file:
https://docs.google.com/spreadsheets/d/13QFnYri6d8xvL9kXw-xAP87n1kT4wh4HwxYtHftMU9g/edit#gid=2094642927
Max's Solution works great! took me over an hour to analyse and finally understand the formula.
for my needs, I did not combine the rows and perform a single evaluation. Instead, I repeated the formula for every row using the following simplified formula (this fixes the alignment bug when there's empty rows)
= JOIN(char(10), ArrayFormula(
IFERROR(
VLOOKUP("["&SPLIT( A10 ,"[]", TRUE) &"]",NOTES,2,0),
"Error")
)
)
the following is a break down of what each part of Max's formula means.
start debugging from the inside(1) to the outside (7)
//(7) Finally, we TRANSPOSE the Columns into Rows
TRANSPOSE(
//(6) Now, we SPLIT the column up with the delimiter “\n!\n”
// that was added during Step (1)
SPLIT(
//(5) we now JOIN back all the columns, adding a new line “char(10)" before every column
JOIN(
char(10) //prepend with new line
//(4) The Magic !! ARRAYFORMULA enables the display of values returned from an array formula into multiple rows and/or columns
// Result is now displayed across multiple columns
,ArrayFormula(
IFERROR(
//(3) We can now do a VLOOKUP for each of the split search key
// (but only The first result is displayed)
VLOOKUP(
“[“ //reinsert the [ back after the split
//(2) Now, SPLIT up everything using delimiter “!”(new Row) And “[“ (new item)
& SPLIT(
//******** START FROM HERE*********
//(1) - take all the rows of interest, and then
// JOIN them together with a “!<SPACE>”
JOIN(
"! " //delimiter !<SPACE> ?
,A1:A4) //text to join (all the rows of interests)
,"![“
,TRUE) // split by each
,NOTES //Named range of interest
,2 //take second second column
,FALSE)
,”!”) // insert ! If error
) //ArrayFormula
) //JOIN
,char(10)&"!"&char(10) //delimiter "\n!\n” for split
,FALSE // do not split by each
) //SPLIT
) // TRANSPOSE

Resources