How can I get the row number in Google Sheets queries? 2

How can I get the row number in Google Sheets queries?

In Google Sheets, users can easily retrieve the row number in a query by using the ROW function. This function returns the row number of a specified cell or range, allowing users to easily track and reference the location of data within their sheet. By including the ROW function in a query, users can efficiently and accurately retrieve the row number, providing a useful tool for organizing and analyzing data in Google Sheets.

Google Sheets Query: Get Row Number in Queries


You can use the following syntax in a Google Sheets query to add a column that contains row numbers:

=ARRAYFORMULA(QUERY({A2:B11, ROW(A2:B11)}, "SELECT Col1, Col3 WHERE Col1 = 'Mavs'",0))

This particular query will select the values from column Col1 (column A) and Col3 (column C) where the value in Col1 is equal to “Mavs” – this query also assumes that Col3 is blank so that Col3 will simply be used to find the row numbers.

Note: We must wrap the QUERY in an ARRAYFORMULA so that we can get the row numbers for each row and not just the first row.

The following example shows how to use this syntax in practice.

Example: Get Row Number in Google Sheets Queries

Suppose we have the following dataset that contains information about various basketball players:

We can use the following formula to select all of the values in column A where the team is equal to “Mavs” and select the row number for each row as well:

=ARRAYFORMULA(QUERY({A2:B11, ROW(A2:B11)}, "SELECT Col1, Col3 WHERE Col1 = 'Mavs'",0))

The following screenshot shows how to use this query in practice:

Google Sheets query row number

The query returns the values from column A where the team is equal to “Mavs” along with the row number for each of these rows.

From the output we can see that the players on the “Mavs” team are found in rows 2, 3, and 6 in the original dataset.

Cite this article

stats writer (2024). How can I get the row number in Google Sheets queries?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-get-the-row-number-in-google-sheets-queries/

stats writer. "How can I get the row number in Google Sheets queries?." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-get-the-row-number-in-google-sheets-queries/.

stats writer. "How can I get the row number in Google Sheets queries?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-get-the-row-number-in-google-sheets-queries/.

stats writer (2024) 'How can I get the row number in Google Sheets queries?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-get-the-row-number-in-google-sheets-queries/.

[1] stats writer, "How can I get the row number in Google Sheets queries?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I get the row number in Google Sheets queries?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top