Only odd columns in arrayformula on google sheets - google-sheets

I have multiple columns that I need to stack into one column. But I only want to have odd columns in the list.
This is the formula I'm working with, which works to get all in one column. But not just odd ones
=TRANSPOSE(SPLIT(ARRAYFORMULA(CONCATENATE(TRANSPOSE(FILTER(A:D,A:A>0)&""))),""))
https://docs.google.com/spreadsheets/d/1yAPw13VE7uclP0ILzUYxZBgLGid9PrZXpWmhuEgi1S0/edit?usp=sharing
Appreciate the help.

You can also use QUERY with 'skipping 2' option. This takes only every 2nd row so to make it useful you have to transpose your range first. Then you FLATTEN your columns.
As you can see, there's a different order of values:
=flatten(query(transpose(A1:D4),"select * skipping 2 "))

This should do it:
=QUERY(FLATTEN(FILTER(A:D,ISODD(COLUMN(A:D)))),"Select * Where Col1 Is Not Null")
FILTER filters in all cells from odd columns.
FLATTEN makes one column of all of the FILTERed results.
QUERY weeds out blank rows.

Related

Unnest two columns in google sheet

I have a table like this one here (basically it's data from a google form with multiple choice answers in column A and B and non-muliple choice data in column C) I need a separate row for each multiple choice answer.
Column A
Column B
Email
A,B
XX,YY
1#gmail.com
A,C
FF,DD
2#gmail.com
I tried to un-nest the first column and keep the remaining columns like this
enter image description here
I tried several approaches I found with flatten and split with array formulas but I don't know where to start really.
Any help or hint would be much appreciated!
You can use the split function on the column A and after that, use the index function. Considering the table, you can use:
=index(split(A2,","),1,1)
The split function separate the text using the delimiter indicated, returning an array with 1 line and 2 columns; the index function will return the first line and the first column from this array. To return the second element from the column A, just change to
=index(split(A2,","),1,2)
I think there's no easy solution for this. You're asking for as many combinations of elements as multiple-choice elections have been made. Any function in Google Sheets has its potentials and limitations about how many elements it can express. One very useful formula here is REDUCE. With REDUCE and sequences of elements separated by commas counted with COUNTA, you can stablish this formula:
=QUERY(REDUCE({"Col A","Col B","Email"},SEQUENCE(COUNTA(A2:A)),LAMBDA(z,c,{z;LAMBDA(ax,bx,
REDUCE({"","",""},SEQUENCE(ax),LAMBDA(w,a,
{w;
REDUCE({"","",""},SEQUENCE(bx),LAMBDA(y,b,
{y;INDEX(SPLIT(INDEX(A2:A,c),","),,a),INDEX(SPLIT(INDEX(B2:B,c),","),,b),INDEX(C2:C,c)}
))})))
(COUNTA(SPLIT(INDEX(A2:A,c),",")),COUNTA(SPLIT(INDEX(B2:B,c),",")))})),
"Where Col1 is not null",1)
Since I had to use a "initial value" in every REDUCE, I then used QUERY to filter the empty values:

list all unique values and count how many times each appears

A spreadsheet contains multiple rows and columns with names (in varying order), the same name can appear in multiple places, but not necessarily in the same column or row.
Looking to list all names and count the number of times each name appears (no duplicates).
Tried the UNIQUE in combination with COUNTIF, but I can't seem to make them work together. :(
I'm sure there's some way of nesting formulas to tabulate the results, but I just can't wrap my head around it.
You can select your whole range in a query like this (change A2:F with your desired range)
=QUERY(FLATTEN(A2:F),"SELECT Col1,COUNT(Col1) where Col1 is not null group by Col1")
See this answer on how to stack unique counts when values are in multiple columns.
For example if your data is in A1:D10:
=UNIQUE({A1:A10;B1:B10;C1:C10;D1:D10})
Will return a (vertical) list of all unique values. Then use countif in a new column on the whole range (rows, columns) with condition on each of the unique values.

FLATTEN skipping blank cells without using UNIQUE

I'm trying to turn an array into a single column without blank cells, considering that the input will always have some blank cells and that there might be repeated values. I'm trying to use FLATTEN but it keeps the blanks and UNIQUE would kill the repeated values, so I can't use.
I also thought about using something like FLATTEN(QUERY(X:X, "select * WHERE col1,col2,col3,col4,col5 IS NOT NULL") but number of columns might be dynamic so I can't say precisely which columns to use.
My input:
Desired output:
Sample sheet here
Any clue?
Use QUERY on the outside:
=QUERY(FLATTEN(YOUR-RANGE-HERE),"Select * WHERE Col1 Is Not Null")
I left an example in your spreadsheet, cell G2.
=flatten(filter(A1:E10;not(isblank(A1:E10))))
or
=flatten(filter(A1:E10;len(A1:E10)))
or
=filter(flatten(A1:E10);len(flatten(A1:E10)))

How to import multiple column values with one condition?

I am having problems in getting the values. I need to get the values of July 10, 2020 to July 25, 2020 under column TL "June Troy". I have tried to do query with importrange and filter with importrange. But I cannot get it right. Please help.
If I understand your question, the following query should work for you:
=QUERY(ARRAYFORMULA(TO_TEXT({importrange("https://docs.google.com/spreadsheets/d/1CQkhI5dZoIUfoKF1aQ8lm1Y8rmOOZapaoYBJw8BJTSE/edit?usp=sharing","Attendance!A1:BC99")})),
"select Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25 where Col7 = 'June Troy' ",1)
Note that since your test data has June Troy on every row, this ends up selecting every row.
More importantly, your "value" columns have mixed data types, both numeric and string values, and QUERY ignores the minority data types and returns blanks for those values. So I included the TO_TEXT function to convert individual cells to text before passing them to the QUERY. And to make the TO_TEXT act on every cell in the range, it is wrapped in an ARRAYFORMULA.
Let us know if this works for you.
UPDATED: To correct formula. Sorry about that.
This is an answer to your second question, which should perhaps be a separate from the first part, since it is a different issue. But yes, you should be able to connect two IMPORTRANGE queries. Consider this formula:
={
QUERY(ARRAYFORMULA(TO_TEXT({importrange("https://docs.google.com/spreadsheets/d/1CQkhI5dZoIUfoKF1aQ8lm1Y8rmOOZapaoYBJw8BJTSE/edit?usp=sharing","Attendance!A1:BC99")})),
"select Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15
where Col7 = 'June Troy' ",1),
QUERY(ARRAYFORMULA(TO_TEXT({importrange("https://docs.google.com/spreadsheets/d/1CQkhI5dZoIUfoKF1aQ8lm1Y8rmOOZapaoYBJw8BJTSE/edit?usp=sharing","Attendance!A1:BC99")})),
"select Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25
where Col7 = 'June Troy' ",1)
}
Basically, you would have two very similar queries. In my example, I point them both at the same sheet, but you can point to a different link, for one of the queries.
They are wrapped in braces, "{...}", to form a new array. And most importantly, the first query has a comma, ",", after it, to force the result of the second query to be in adjacent columns, on the same rows. If you separate the two queries with a semi-colon, ";", the result of the second query would be added as rows underneath the first query, not in columns beside it.
HOWEVER, I think this causes an error if the two queries don't both return the same number of rows. So that will depend on your data. But since you are getting related columns, I'm assuming they should return the same number of rows. If not, share the data from your two sample sheets, and what the desired outcome should look like.

Google Sheet - Transform two columns into one column using arrayformula (more than 50,000 characters)

I'm using Google Sheets and looking for an arrayformula that able to take a list in two columns and arrange it alternately in one column. The sheet contains about 5,000 rows, each row has more than 35 characters.
I tried this:
=transpose(split(join(" ", query(transpose(B5:C),,50000)), " "))
But then I got this message:
Please take a look at the sheet here:
https://docs.google.com/spreadsheets/d/11T1Roj1trviOSiiTZS292-4l3oODid7KLi9oGz3Z66o/edit#gid=0
Assuming your 2 columns are A and B, this formula will "interlace" them:
=query(
sort(
{arrayformula({row(A1:A3)*2, A1:A3});
arrayformula({row(B1:B3)*2+1, B1:B3})}
),
"select Col2")
Explanation, unwrapping the formula from the inside:
Each value gets a unique number, based on its row number times 2 (+1 for the 2nd column)
Everything is sorted based on this number
Only the 2nd column is extracted for the result.
There is a function for this called FLATTEN().
This works perfectly as a general solution since it takes an array of any size and outputs the items in the order they appear left-right-top-down (See here).
It can be combined with TRANSPOSE() to accomplish the same thing but in the horizontal case, and if needed blank cells can be omitted with FILTER().
EDIT:
My sincere apologies, I did not read the question carefully enough. My response is incorrect.
This should work:
={B5:B12;C5:C12}
just be careful to NOT change it to
={B5:B;C5:C}
This will start an infinite loop where the spreadsheet will increase the amount of rows in the spreadsheet to allow this output column to expand, but in doing so increases the length of the 2 input columns, meaning the length of the output column increases even more, so the spreadsheet tries adding more rows, etc, etc. It'll make your sheet crash your browser or something each time you try to open it.
In Row5:
=ArrayFormula(offset(B$5,INT((row()-5)/2),iseven(row())))
Would need to be copied down however.

Resources