I have a column (A1:A) with URLs of the Sheets I want to IMPORTRANGE. The problem is it's open end and I can't just do
={IMPORTRANGE(A1,"Sheet1!A1:A");IMPORTRANGE(A2,"Sheet1!A1:A")}
as the list of URLs is open end (indefinite). Since I cannot use ARRAYFORMULA with IMPORTRANGE, I was wondering if there is an alternative to it. I'd also like to have a URL next to IMPORTRANGE data, so I know what URL the data shown came from. Maybe someone has a clue.
https://docs.google.com/spreadsheets/d/1YhLJpy_p39pDvTKfjyOKQMN0W_TDz95E9XsmtOJV-GQ
Maybe it would be better to use script for that. IMPORTRAGE not working inside ARRAYFORMULA is usually solved with importing using scripts.
In case of formulas with import failure tolerance and source markings here are a few solutions.
Solution 1 - many QUERY, same number of IMPORTRANGE
Try this:
=QUERY(
ARRAYFORMULA(
{
IFERROR(QUERY(IMPORTRANGE(A2; B2); "SELECT '" & A2 & "', Col1 WHERE Col1 IS NOT NULL"); {""\ ""});
IFERROR(QUERY(IMPORTRANGE(A3; B3); "SELECT '" & A3 & "', Col1 WHERE Col1 IS NOT NULL"); {""\ ""});
IFERROR(QUERY(IMPORTRANGE(A4; B4); "SELECT '" & A4 & "', Col1 WHERE Col1 IS NOT NULL"); {""\ ""})
}
);
"WHERE Col2 IS NOT NULL
LABEL Col1 'Source',
Col2 'Imported Data'"
)
Solution 2 - one QUERY, twice the IMPORTRANGE
You can use IFERROR in case import will go wrong.
Here is a possible solution for you (IFERROR and source URLs) (one formula in E1):
=QUERY(
ARRAYFORMULA(
{
IFERROR({IF(SEQUENCE(ROWS(IMPORTRANGE(A2; B2))); A2)\ IMPORTRANGE(A2; B2)}; {""\ ""});
IFERROR({IF(SEQUENCE(ROWS(IMPORTRANGE(A3; B3))); A3)\ IMPORTRANGE(A3; B3)}; {""\ ""});
IFERROR({IF(SEQUENCE(ROWS(IMPORTRANGE(A4; B4))); A4)\ IMPORTRANGE(A4; B4)}; {""\ ""})
}
);
"WHERE Col2 IS NOT NULL
LABEL Col1 'Source',
Col2 'Imported Data'"
)
Related
I have a range of data on column A and B. In Column D , i have a reference for the shotID. I want to make a list for the artist involved for specific shotID.
In E2 i use this :
=JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2))
then copy down to E3,E4. It works as i expected, but i want to do it using array formula. So only use single formula in E2 and that doesn't work that simple :
=arrayformula( JOIN( "," , FILTER($B$2:$B, $A$2:$A= D2:D4)) )
How can i do this ?
One more possibility that I learned from player0 and surprised he didn't suggest...
=ARRAYFORMULA(SPLIT(TRANSPOSE(SUBSTITUTE(TRIM(QUERY(QUERY(A2:B&{"|",CHAR(10)},"select MAX(Col2) where Col1<>'|' group by Col2 pivot Col1"),,100)),CHAR(10),",")),"| ",0))
take:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(SUBSTITUTE(
FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(
FLATTEN(A2:A&"×"&B2:B&","&"×"&B2:B), "×"),
"select Col1,max(Col2) where Col2 is not null group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), " ", "×", 1), "×")), ",$", ))
You could also try:
={unique(A2:A),arrayformula(transpose(substitute(trim(query(if(A2:A<>transpose(unique(A2:A)),,B2:B),,9^9))," ",", ")))}
Cannot figure out how to pull the results of a query with multiple rows and columns into single cells and find their details from my lookup table. Any help is greatly appreciated.
Trying this
=ArrayFormula(
QUERY({
QUERY({A4:A16,TEXTJOIN(",",TRUE,B4:C16)}, "SELECT Col1, Col2, Col3 WHERE Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'Full Result'")
}, "SELECT Col2 WHERE Col1 = Col1")
)
Sheet to help
It's always a headache trying to mix Query with ArrayFormula. They don't go well together.
I arrived at a nice formula, but the catch is that it relies on you sorting your data by Core Item first. You can easily achieve this with:
=SORT(A4:C16)
For this example, I placed this formula is cell N4. Then your resultant formula is:
=ArrayFormula(
{
"Core ID", "Full Result";
UNIQUE(FILTER(N4:N,N4:N<>"")),
SUBSTITUTE(
TRANSPOSE(
SPLIT(
REGEXREPLACE(
TEXTJOIN(
",",
,
UNIQUE(
TRANSPOSE(
IF(
TRANSPOSE(FILTER(N4:N,N4:N<>""))=FILTER(N4:N,N4:N<>""),
FILTER(O4:O,O4:O<>"")&
" ("&
VLOOKUP(FILTER(O3:O,O3:O<>""),A23:B53,2,)&
") - "&
FILTER(P4:P,P4:P<>"")&
" ("&
VLOOKUP(FILTER(P4:P,P4:P<>""),A23:B53,2,)&
")",
";"
)
)
)
),
",(;,)+",
";"
),";"
)
),
",",
CHAR(10)
)
})
It uses the Group Concatenate method I've adopted for stuff like this with UNIQUE, TRANSPOSE, and IF. This can probably be solved without using the precalculated SORT by substituting all instances of the N4:N, but doing it this way saves on computation time. If you need it gone, you can also hide the column or stow it in another sheet.
If you are ok breaking apart your formula then this would be an acceptable approach.
Start by Building your query criteria.
=ArrayFormula(
QUERY({QUERY({A4:A16,ArrayFormula(B4:B16&" ("&VLOOKUP(B4:B16,A23:B53,2,false)&") -
("&VLOOKUP(C4:C16,A23:B53,2,false)&")")}, "SELECT Col1, Col2 WHERE
Col1 MATCHES 'Core 1|Core 2|Core 3' LABEL Col1 'Core ID', Col2 'ALL Result'")},
"SELECT Col1, Col2 WHERE Col1 = Col1"))
Then in another column get the unique values and lastly, join the filtered values.
=UNIQUE(E4:E17)
=Join(Char(10),FILTER(F4:F12,E4:E12 = H4))
The downside to this is you will need to have multiple columns to achieve your desired result but it is easy to follow. Good luck!
I have a column of search terms and would like to find out all the two-word phrases in this column and the frequency of each of all them. Does anyone know of a formula in Google Sheets that can help me accomplish this?
=ARRAYFORMULA(IFERROR(QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
and Col3=''
group by Col2
label count(Col2)'frequency'"),
QUERY(IF(SPLIT(A1:A, " ")>0, A1:A, ),
"select Col2,count(Col2)
where Col2 is not null
group by Col2
label count(Col2)'frequency'")))
pste in C2 and drag down:
=COUNTA(FILTER(A:A, SEARCH("*"&B2&"*", A:A)))
How do I convert this:
=if(ISNA(sum(QUERY(importrange("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0","Transfer!C$2:E"),"SELECT Col3 WHERE Col1 = '" & Sheet1!B$2:B & "' ",0))),"0",sum(QUERY(importrange("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0","Transfer!C$2:E"),"SELECT Col3 WHERE Col1 = '" & Sheet1!B$2:B & "' ",0)))
into the array formula in Google Sheets?
in my opinion, it would be pretty much an overkill if it would be possible. instead I recon to do this:
use side columns (or create a new sheet in PRC Records spreadsheet) and paste this formula there:
=QUERY({Transfer!A1:H}, "select Col3, sum(Col5)
where Col3 is not null
group by Col3
label sum(Col5)'FG Qty'", 1)
and then use this formula in J2 cell over on the MO Listing spreadsheet:
=ARRAYFORMULA(IF(LEN(B2:B), IFERROR(VLOOKUP(B2:B,
IMPORTRANGE("1QNYU1Kb1rtx-n4tMRamHJuvYt_9kGMfhGZZs_opuJr0",
"Transfer!L2:M"), 2, 0), 0), ))
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).