Javascript required
Skip to content Skip to sidebar Skip to footer

How to Limit Number of Rows in Google Sheets

The Query function in Google Sheets is a useful tool for looking up and filtering data onto your online spreadsheet. With spreadsheets, you can really get lost in the data, but this function can steer you right on track. You can review this usual function here, and be able to create really powerful and helpful spreadsheet tools in combination with other functions.

Once you recall data into your spreadsheet, however, there will be a possibility that you are met with an unprecedented amount of information and it becomes difficult to wade through the rows and columns. You will want to know how to limit the number of rows that have been recalled.

So, how should we proceed?

The Anatomy of the QUERY Function

The syntax (or the way we write) the QUERY function is as follows:

          =QUERY(data,query,[headers])        

Let's break the function down to understand each term:

  • = the equal sign is how we begin any function in Google Sheets.
  • QUERY our function, which will take the data, query, and headers inputs to create database commands.
  • data is the range that you want to execute your query upon.
  • query is the reference to the cells where the query is placed. This is an important part of the function of what we want to accomplish by limiting the number of rows. Note that your query input must be enclosed in quote symbols to work properly.
  • headers is the optional attribute that you can use to determine the number of headers at the top of the data. It can be left blank.

A Real Example of Using the QUERY Function

Using the QUERY function is a super versatile way of understanding the data in Google Sheets.

As you can see in the data above, the QUERY function is used to determine the customers who acquired the order sizes above 15 lots, despite the variant that they order. The function outputs the names of those who ordered the most.

The function takes three arguments. So in the equation, it will look like:

          =QUERY(A1:D16,"Select B,D where D >15")        

Here's what the example does:

  • We actively selected the cell where we write our formula, and we use the QUERY function to determine which customers bought more than 15 lots.
  • We selected the entire data table, A1:D16.
  • Our Query wants to limit the data to the customers that order more than 15 lots of any variant of product.
  • Note that in our example, the query attribute uses the greater than function. This is the same thing as applying 16 and above to the formula.

This simple problem can be practiced to perfection. Use the link below to get a copy of this problem set:

How to Limit Number of Rows in Google Sheets Query

There are a number of ways that you can limit the number of rows for your Google Sheets Query. We are going to tackle the simplest method for this.

How to Limit Number of Rows in Google Sheets Query Using the Limit Input

  1. Click on a cell to make it active. This is where we will write the formula, which will also be where the query that we are looking at will populate.

How to Limit Number of Rows in Google Sheets Query

  1. Next, type in the equal sign in order to start our function, then the name of our function, QUERY.

How to Limit Number of Rows in Google Sheets Query

  1. You will notice that a more detailed description will pop up. This will help you determine and help you with the inputs and results of your query.

How to Limit Number of Rows in Google Sheets Query

  1. Select the data range. In the example, we will highlight cells A1: E16, so we are including the headers of the table.

How to Limit Number of Rows in Google Sheets Query

  1. Here we input the actual query. The syntax is straightforward as if you are talking to Google Sheets in English. We aim to get the first three items in the list or limiting the query to 3 rows or items. We want to get the first three Customer Names (which is column B) and the Order Prices (which is column E) in this example. Input "select B,E limit 3" into the formula.

How to Limit Number of Rows in Google Sheets Query

  1. Hit enter and the data you expect should populate the following cells. You will notice that it includes the header, and then 3 rows of data, as expected from the query presented.

How to Limit Number of Rows in Google Sheets Query

Note that if you have other requirements, such as getting the 3 biggest Order Prices in the set, you can use that logic in the Query section, too.

How to Limit Number of Rows in Google Sheets Query Using the Offset Function

Another way to limit the number of rows is by using the OFFSET function in Google Sheets. However, this function does the opposite of the example above – instead of taking the first x rows of the list, Offset does exactly what it says and omits the first x rows off the list.

  1. Again, start off with the QUERY function with an equals sign.

How to Limit Number of Rows in Google Sheets Query

  1. Type in the QUERY, add the open parenthesis and add the data range like in the previous example.

How to Limit Number of Rows in Google Sheets Query

  1. For the Query attribute, trying to limit the list to the last 3 items in the list, input "select B, E Offset 12" into the formula. 12 is chosen because there is a total of 15 items on the table.

How to Limit Number of Rows in Google Sheets Query

  1. Hit enter and the data you expect should populate the following cells. You will notice that it includes the header, and then 3 rows of data, as expected from the query presented.

How to Limit Number of Rows in Google Sheets Query

There you have it! You are now able to limit theQUERY functions's number of rows in Google Sheets as you wish, without disturbing the integrity of your data. Now that you have a grasp on how to combine data visualization styles in your spreadsheets, you can combine this with other Google Sheets formulas to make really powerful data documents!

Get emails from us about Google Sheets.

Our goal this year is to create lots of rich, bite-sized tutorials for Google Sheets users like you. If you liked this one, you'll love what we are working on! Readers receive ✨ early access ✨ to new content. There will be no spam and you can unsubscribe at any time.

How to Limit Number of Rows in Google Sheets

Source: https://www.sheetaki.com/how-to-limit-number-of-rows-in-google-sheets-query/