FLATTEN skipping blank cells without using UNIQUE - google-sheets

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)))

Related

Only odd columns in arrayformula on 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.

How do I add up the value of column B if column A meets a certain condition for each value in column A with one formula?

Below is an example of the values I'm trying to add. My goal is not to use the filter formula for every line again. This is because it takes a lot of resources from the processing power that google sheets uses.
The words in the left list below occur several times in combination with a certain number. I want to have a unique list as shown on the right where the values from the left row add up when the words are equal (without using a filter formula for each line).
This formula
=arrayformula(vlookup(A:A, A:B, 2, FALSE)))
comes very close, but returns only one value even though there are multiple matches. I want all values that matches returned.
try:
=QUERY(A:B, "select A,sum(B) where A is not null group by A label sum(B)'summed'", 1)

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.

Combine multi-row array into single row

I'm trying to combine the multi-row results of a QUERY into a single row.
The first result (A4:L4) should remain as-is with the following result added to the end of the previous result in the same row keeping blank values in place. The header will be removed, so that doesn't need to be considered.
I've tried nesting QUERY and FILTER but am only managing to get a single column or transpose the whole array.
=QUERY({journeySquads!A:M},"SELECT Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&A1&"'",1)
You could also use flatten (no restriction on string length)
=transpose(query(flatten(query(A2:M,"select * where A='test'"))," select Col1 where Col1 is not null"))
Well, I figured it out...
=SPLIT(TEXTJOIN("| ",,QUERY({journeySquads!A2:M},"SELECT Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13 WHERE Col1='"&A1&"'",0)),"|")

Query particular row + remove X columns + and sum the rest in one formula?

I have a CSV file that I'm pulling from a database. It's in an awkward layout so I need to reorganise it and display the result in a separate sheet.
Here is a dummy example of the data structure I get.
https://docs.google.com/spreadsheets/d/1sTfjr-rd0vMIeb3qgBaq9SC8felJ1Pb4Vk_fMNXQKQg/edit?usp=sharing
It looks like that. The database grows every day by date and sometimes countries so I need to account to that in my formula.
I need to pull data per each country and display it by date.
I don't need data from Column A, C and D. And when there are multiple states I need to sum them up in one column.
It should look like this and keep growing downwards. I'm gonna use this table for a graph chart
What I've tried so far
=TRANSPOSE(QUERY(IMPORTRANGE("url_to_a_separate_sheet_where_I_importing_a_row_csv_file", "CSV-source-sheet!A1:500"), "SELECT * WHERE Col2='Germany'"))
This works, kinda. But pulls in unnecessary columns and I can't figure out how to sum countries with multiple states. When I add select sum(*) it gives me a big and long error. I assume it might be because of unnecessary columns that the formula cant sum up and I don't know how to omit them. I'm stuck
I tried offset and skipping no luck. Any ideas?
try:
=ARRAYFORMULA(TRANSPOSE(QUERY({Sheet2!B:B, Sheet2!E:BE},
"select Col1,"&TEXTJOIN(",", 1,
"sum(Col"&ROW(INDIRECT("Sheet2!A2:A"&COUNTA(Sheet2!1:1)-5))&")")&"
where Col1 is not null
group by Col1
label Col1'Date'", 1)))
spreadsheet demo

Resources