Google-sheets – How to link to source cell from filter output

google sheetsgoogle-workspace

I have a simple query that outputs columns A and B of a project dataset, when the value in column A is not empty:

=QUERY(Projects!A2:B, "SELECT A,B WHERE A<>''")

This creates an easy to scan highlight of the important project data (in my case, project name and next action item). However, the project details are in another tab, so if I want to examine the project, I have to copy the name, go to the tab, and search for the project.

It would be super nice if the output of the QUERY could automatically hyperlink to the source data. Or maybe there is a hotkey I can press to jump to the source. Does this feature exist?

Best Answer

You have some project transaction data that you query. For each project, there is additional static data in another sheet. When you query your transaction data you want to create a hyperlink to the relevant project on the project sheet.

You have a query that you already use: =QUERY(Projects!A2:B, "SELECT A,B WHERE A<>''"). Insert this in your output sheet in cell A1

  • From your project details sheet, copy the sheet url up to and including the gid. This will look like this. "https://docs.google.com/spreadsheets/d/1tvshJ...../edit#gid=1448462430"

  • Paste the url into the following formula replacing the section labelled "<>"

  • Insert this formula in cell C1, beside the query: =array_constrain(ARRAYFORMULA({HYPERLINK("https://docs.google.com/spreadsheets/d/<<insert sheetID and gid here>>&range=A"&match(A1:A,Project_details!A2:A5,0)+1,"Link to "&A1:A)}),COUNTA(A1:A),1)


Explanation:

  • The formula creates a hyperlink for the project name in Column A.
  • The hyperlink url is built in three parts:
    • the main body is the url of the project details sheet. You have copied/pasted this into the formula.
    • the column of the linked range is provided by &range=A
    • the row of the linked range is provided by the match function. Note that the actual function is match +1; the "1" allows for the header row on the product details sheet.
  • the formula is wrapped in an arrayformula so that it automatically calculates results for every row.
  • array_contrain is used to limit the output. If not used, the arrayformula would calculate for every row of the sheet - even though it might display output in the rows where there is a value in Column A

Say you have sheet called "Projects" that contains project transaction data. The sheet might look like this:

Project Transaction data

Project transaction data


You also have a sheet containing further static details of each project. Say, this sheet is called "Project_details" and it might look like this:

Project details

Project details


Your output sheet will contain two formula; one in Cell A1 and another in Cell C1. The output should look like this:

Query output and hyperlink

Query output and hyperlink