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) ''
")
0

2 Answers 2

1

Sample formula is:

=QUERY({A:B},"select * where Col1 = '"&JOIN("' or Col1 = '",FILTER(D2:D,D2:D<>""))&"'")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.