You can include a row number in a query()
by using an { array expression }, like this:
=arrayformula( query({A2:B, row(A2:B)}, "select Col1, Col3 where Col2 = 1", 0) )
In the query statement, Col1
is column A
, Col2
is column B
, and Col3
is the "virtual" column that contains row numbers. These "ColX" type column references need to be used whenever the data is not a spreadsheet range or a reference, but a computed array such as an arrayformula()
result or an { array expression }.
The arrayformula()
wrapper is required here to evaluate the row()
function over a range of cells rather than just the top left cell.