HomeGoogle DocsSpreadsheetRound Numbers in Google Sheets Query - Workaround

Round Numbers in Google Sheets Query – Workaround

Published on

The ROUND() function is not part of Google Sheets Query. Then how do we round numbers in Google Sheets Query? Is this possible?

As far as I know, there is no Query clause that we can use to round a number. But there are two methods.

The Query FORMAT clause lets us to visually round numbers. I mean to format the numbers as rounded. If you really want to round (not format) numbers in Google Sheets Query, then I have a workaround.

In this post, I have included the FORMAT clause as well as the said workaround to round numbers in Google Sheets Query.

I have already explained how to format numbers in Query. If you haven’t read that yet, here is the link – How to Format Date, Time, and Number in Google Sheets Query.

Rounding in Query Using the Format Clause

I have two examples for rounding in Query in Google Sheets. In the first example, I will simply round a column in data. In the second example, I will round an output column of an arithmetic operation.

QUERY(data, query, [headers])

Example # 1 – Just Visually Rounding (Formatting) Numbers and Percentages

The following table (please jump to the first image below) contains the gold price performance in Europe during the last one year in specific durations (time frame) as on 25/07/2020.

The data is not important to us or may not be accurate. I’ve used it only for example purpose. We are just rounding the second and third columns in this data using Query.

I have selected this data (A1:C) because we can apply the number as well as the percentage formatting at a time. As you can see the column B contains amount (numbers) and the column C contains percentage changes.

=query(A1:C,"Select * format B '#',C '#%'")

See how I have used the format clause for rounding in Query function in Google Sheets.

Rounding number and percentage in Query

Actually the number is not rounded. It’s just visually rounded. Click cell F2 or G2 to see the underlying value on the formula bar. In F2 it will be 361.67, not 362 and in G2 it will be 28.47%, not 28%.

Example # 2 – Visually Rounding (Formatting) Numbers in a Calculation Column

Here I am going to apply rounding to B*C. I mean, I am going to use the asterisk arithmetic operator in my Query formula and round that output.

=query(A1:C,"Select A, B, C, B*C label B*C'Amt' format B*C '0'",1)
Rounding calculation column in Query

In the Select clause, I have selected columns A, B, C, and B*C. The fourth column formatted using the Format clause to visually rounding numbers in Query.

Since the fourth column is an output column I have used the Label clause to label/name it.

Must Read: What is the Correct Clause Order in Google Sheets Query?

Rounding in Query Using the Round Function

As I’ve already said, in the above two examples, we were formatting numbers/percentages to make it appear as rounded. If you really want to do rounding in Query, you may please follow the below workaround.

Formula as per Example # 1

If you follow the example # 1 above, the Query formula to round numbers in cell E1 would be as follows.

=ArrayFormula(query({A1:A,round(B1:B),round(C1:C,2)},"Select * where Col1 is not null label Col2'Amount', Col3'%'"))

The Round function has been used in the Query Data.

There are three columns – Change, Amount, and %. We want to keep the first column as it is as it’s a text column. The second column contains numbers and the third column contains percentage values.

To round the number column we can use any of the ROUND, ROUNDUP, or ROUNDDOWN functions. Regarding the percentage column, even though we can use the above three functions, there is a slight difference in usage.

For example, if you want to round a value to 0 decimal places, to round a number column you can use round(B1:B) whereas to round a percentage column use round(C1:C,2). The same has been explained here in detail – How to Round Percentage Values in Google Sheets.

Formula as per Example # 2

Here you need to use multiple Query formulas as combined. It’s simple to understand though. Let’s start with this Query in cell E1.

=QUERY(A1:C,"Select A, B, C, B*C",1)
Product - Qty and Rate

Here we want to round the product column H (the 4th column) in Query, right?

Steps to Round Product or Any Formula Output Column in Query

Step 1: Use another Query (wrap the existing one) to extract the first three columns (formula to be inserted in cell E1).

E1 Formula

=QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col1, Col2, Col3",1)

Step 2: Extract the fourth column as above and round it (formula to be inserted in cell H1).

H1 Formula

=ArrayFormula(round(QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col4",1),0))
Rounding in Query using the Round function

Step 3: Combine Step 1 and 2 formulas as per the syntax {step 1, step 2}, which involves the Curly Braces.

For that, cut the formula in cell H1 and combine it with the cell E1 formula as per the syntax above.

E1 Formula

={QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col1, Col2, Col3",1),ArrayFormula(round(QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col4",1),0))}

Step 4: Use the above as Query Data and label the fourth column.

=query({QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col1, Col2, Col3",1),ArrayFormula(round(QUERY(QUERY(A1:C,"Select A, B, C, B*C",1),"Select Col4",1),0))},"Select * where Col1 is not null label Col4'%'",1)

The above formula in cell E1 rounds numbers in Google Sheets Query.

That’s all. Enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

More like this

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...