Display query result in one row instead of two column Google Sheets - google-sheets

=QUERY('BETA - Orders'!$D:$U,"Select Q,K where D='"& I228 &"' and Q is not null and D is not null",0)
I would like to display the result in one column only instead of two rows. The result of the query above is
What I would like to accomplish is

try:
=QUERY(FLATTEN(QUERY('BETA - Orders'!$D:$U,
"select Q,K
where D='"&I228&"'
and Q is not null
and D is not null", 0)),
"where Col1 is not null", 0)

Related

Formatting 3 column array in Google Sheets with unique counts

I have the following data and the work-in-progress formula
=ARRAYFORMULA({unique(A2:A);flatten(UNIQUE(filter(C2:C, A2:A=A2))&": "&countif(filter(C2:C, A2:A=A2),UNIQUE(filter(C2:C, A2:A=A2))))})
How can I go about creating the DESIRED OUTPUT from the dataset?
Google Sheet link: https://docs.google.com/spreadsheets/d/1F-ZRe0hgFWdb318xHtiIGmR-RvxSgv518k9wCUBfCm0/edit?usp=sharing
The query() function lets you get those results, although they will be tabulated in a format that is different from what you requested:
=query(A1:C, "select A, count(A) where C is not null group by A pivot C", 1)
use:
=INDEX(LAMBDA(x, y,
QUERY(FLATTEN({SORT(UNIQUE(FILTER({IFERROR(x/0, "​"), x}, x<>""))),
IF(QUERY(y, "offset 1", )="",,INDEX(y, 1)&": "&QUERY(y, "offset 1", ))}),
"where Col1 is not null offset 1", ))
(A2:A, QUERY(A2:C, "select count(A) where C is not null group by A pivot C")))

how to import rows that contain the same value more than once to another sheet

I have a list of sessions, I want to be able to import the ones that have been rescheduled (along with the new rescheduled session) to another sheet. So under colC one will say 'Rescheduled' and the other will say 'Attended'. So what I'd like to do is grab the participant name, but only if it shows up more than once, so I'd get both the rescheduled session and the new session. I tried using importrange and query, but couldn't quite get it right. How can I do this?
https://docs.google.com/spreadsheets/d/10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc/edit?usp=sharing
try:
=INDEX(REGEXEXTRACT(FLATTEN(QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"))
Formula Explanation:
Take the IMPORTRANGE
Merge all columns into one column
Create a virtual array {}
Pass into QUERY and pivot the data
Transpose the result
Use query to get only needed columns
Transpose back
Compare 1st and 2nd columns and remove
Remove header row
Flatten data into one column and split into the 3 needed columns
and if that's not enough:
=INDEX(REGEXREPLACE(SORT(TEXT(REGEXEXTRACT(FLATTEN(
QUERY(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY({
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C"),
FLATTEN(QUERY(TRANSPOSE(
IMPORTRANGE("10ZWcO9DeBx6KjiyvFvcoBlGk7yw2b8z2gFPi26orOGc", "Sheet1!A1:C")),,9^9))},
"select max(Col4) where Col1 is not null group by Col2 pivot Col3")),
"where Col1 matches 'Rescheduled|Attended'", )),
"where Col1 is not null and Col2 is not null"),
"offset 1", )),
"(\d+/\d+/\d+) (.*) (Att.*|Res.*)"), {
"yyyymmdd\×m/d/yyyy", "#", "#"}), 2, 0, 1, 1), "^(\d+×)", ))
demo sheet

is there a way to use the char(10) function without separating every value?

I am currently using char (10) to merge columns, from a separate tab called "scripts", into one cell based on a name.
=IFERROR(TEXTJOIN(CHAR(10),1,QUERY(Scripts!$A$3:A,"select B, C, D, E where A ='"&A1&"'")))
my information shows up in a list. is there a way to combine columns B+C and then D+E.
row 1 is what my data looks like on "scripts" tab.
row 7 is what the data looks like with the above equation.
row 12 is what i would like the equation to do.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A1:A, QUERY(
{Scripts!A:A, Scripts!B:B&" "&Scripts!C:C&CHAR(10)&Scripts!D:D&" "&Scripts!E:E},
"where Col1 is not null"), 2, 0)))
update:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(QUERY(
{Data!A2:A&"×", CHAR(10)&TEXT(Data!B2:B, "m/d/yy")&
CHAR(10)&Data!C2:C&", "&Data!D2:D&", "&Data!E2:E, ROW(Data!A2:A)},
"select max(Col2) where not Col1 starts with '×' group by Col3 pivot Col1")
,,9^9)), "×")), "^"&CHAR(10), ))

Google Sheets pivot - remove empty rows

I have a transaction table and I need to show open balances for it.
I didn't find how to hide empty rows. I want to show just GREEN rows. I tried to use filter but it doesn't work
Test sheet
try:
=ARRAYFORMULA({QUERY(REGEXREPLACE(""&QUERY(A1:D,
"select A,B,sum(D) where A is not null group by A,B pivot C"),
"^0$", ),
"where Col3 is not null or Col4 is not null");
{"Grand Total", "", INDEX(QUERY(A1:D,
"select sum(D) where A is not null pivot C"), 2)}})

How to use ARRAYFORMULA in query where clause?

In cell C1:C of my table I got 6 rows with ticket id's. I like to search different spreadsheets to search for those ticket id's and calculate the total hours spent on that ticket.
I have it working using the following formula:
=QUERY({IMPORTRANGE("SPREADSHEETID";"B3:B")\ARRAYFORMULA(TO_PURE_NUMBER(IMPORTRANGE("SPREADSHEETID";"F3:F")-IMPORTRANGE("SPREADSHEETID";"E3:E")))};"SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''")
In this example, C1 is where the ticket ID can be found.
Now I thought I could just wrap QUERY in a ARRAYFORMULA and use C1:C instead of just C1 but that won't work. Now I could just copy and paste the above formula in every cell but there must be a cleaner way.
ANSWER
I used the following formula to make it work, thanks to Max's answer below.
=QUERY(
{
IMPORTRANGE("SPREADSHEETID";"B3:B")\
ARRAYFORMULA(
TO_PURE_NUMBER(
IMPORTRANGE("SPREADSHEETID";"F3:F") - IMPORTRANGE("SPREADSHEETID";"E3:E")
)
)
};
"
SELECT Col1, SUM(Col2)
WHERE Col1 = '" & JOIN("' OR Col1 = '";FILTER(C:C; C:C <> "")) & "'
GROUP BY Col1
LABEL SUM(Col2) ''
")
Sample formula is:
=QUERY({A:B},"select * where Col1 = '"&JOIN("' or Col1 = '",FILTER(D2:D,D2:D<>""))&"'")
No, one cannot create an array of query strings and use arrayformula(query(...)) to run them all at once.
Alternative: instead of
SELECT SUM(Col2) WHERE Col1 = '"&C1&"' GROUP BY Col1 LABEL SUM(Col2) ''
use the query
SELECT Col1, SUM(Col2) GROUP BY Col1
elsewhere on the sheet, and then use vlookup to look up the sum for each value of Col1 that you want. vlookup can be used inside of arrayformula like this:
=arrayformula(vlookup(C1:C10, E:F, 2, 0))
looks up each of values in C1..C10 in the column E (exact match required) and returns the corresponding value in column F (2nd column of the searched range).

Resources