Search code examples
arraysimportcountgoogle-sheets-formulagoogle-query-language

Query importrange to count to number of times a value is in a column


In this google sheet I have text data in range O3:O: https://docs.google.com/spreadsheets/d/1xNFVHLnQGkRgZdLmejCyU0BByOPBY8NMoIYj6SkTFGY/edit?usp=sharing

My objective: Query + importrange to count the number of times a value in cell A3 within sheet2! appears within the importrange "/1xNFVHLnQGkRgZdLmejCyU0BByOPBY8NMoIYj6SkTFGY/edit#gid=0", "June!O3:O"

This is what I have so far but returns #value

=QUERY(IMPORTRANGE("/1xNFVHLnQGkRgZdLmejCyU0BByOPBY8NMoIYj6SkTFGY/edit#gid=0", "June!O3:O"),"select Col1, count(Col1) where Col1='"&A3&"' group by Col1, Col1 order by Count(Col1)", 1)

Update: I have now been able to get the correct count to appear but, this formula also returns searched value in the column the query is added and text 'count' above the returned result.

I just need the count to appear in the same cell as the formula without anything else returned

=QUERY(IMPORTRANGE("/1xNFVHLnQGkRgZdLmejCyU0BByOPBY8NMoIYj6SkTFGY/edit#gid=0", "June!O3:O"),"select Col1, count(Col1) where Col1='"&A3&"' group by Col1", 0) 

Solution

  • try:

    =COUNTA(IFNA(QUERY({IMPORTRANGE(
     "1xNFVHLnQGkRgZdLmejCyU0BByOPBY8NMoIYj6SkTFGY", "June!O3:O")}, 
     "where Col1='"&A3&"'", 0)))