HomeGoogle DocsSpreadsheetCreating Month Wise Summary in Google Sheets (Query Formula)

Creating Month Wise Summary in Google Sheets (Query Formula)

Published on

Creating a month-wise summary report in Google Sheets is not a difficult task. A few good options are available, such as the Pivot Table, the SUMIF function, and the QUERY function.

In Excel, there are plenty of options. We can use menu commands such as Data > Subtotal and Insert > Pivot Table and use functions such as SUMIF, SUMIFS, etc.

In Google Sheets also, you can adopt all these methods except the Subtotal. In addition, we can use the QUERY function, the most versatile function in Google Sheets.

So, in this tutorial, let’s learn how to create a month-wise summary report in Google Sheets with the help of the QUERY function.

How to Create a Month Wise Summary Report in Google Sheets

Sample Data:

Sample Data to Create a Month Wise Summary Report in Google Sheets

What are we going to do with this data?

We will prepare a month-wise summary of each product by grouping the date and product column.

Please follow the step-by-step instructions below.

Step 1: Group by Month

Syntax: QUERY(data, query, [headers])

The following QUERY formula can be used to group a date column by month and sum another column in Google Sheets:

=QUERY(A1:F,"SELECT MONTH(A), SUM(F) GROUP BY MONTH(A)",1)

The formula takes three arguments:

  • The range of data to be queried, which is A1:F in this case.
  • The query statement, which is SELECT MONTH(A), SUM(F) GROUP BY MONTH(A) within double quotation marks in this case.
  • The number of header rows, which is 1 in this case.
Step 1: Group by Month (Un-Formatted)

The query statement selects the months of the dates in column A and sums the values in column F, grouping the results by month.

The above month-wise summary result in Google Sheets has three issues:

  • The month numbers are ‘incorrect’ because the MONTH scalar function in QUERY returns month numbers as zero-based integers. January is shown as 0, February as 1, and so on.
  • There are blank rows in the result.
  • The labels are not tidy.

Let’s fix these issues first.

The following formula will adjust month numbers.

=QUERY(A1:F,"SELECT MONTH(A)+1, SUM(F) GROUP BY MONTH(A)+1",1)

This one will remove blank rows.

=QUERY(A1:F,"SELECT MONTH(A)+1, SUM(F) WHERE A IS NOT NULL GROUP BY MONTH(A)+1",1)

Now what is left is making the labels tidy. We can use the LABEL clause for that.

=QUERY(A1:F,"SELECT MONTH(A)+1, SUM(F) WHERE A IS NOT NULL GROUP BY MONTH(A)+1 LABEL MONTH(A)+1 'MONTH', SUM(F)'TOTAL'",1)
Step 1: Group by Month (Formatted)

You May Like: What is the Correct Clause Order in Google Sheets Query?

We have created a basic month-wise summary report in Google Sheets. It contains just two columns: A month column and a total column.

Step 2: Group by Month and Product

To group by Product, include it in both the SELECT and GROUP BY clauses. Here is the final formula:

=QUERY(A1:F,"SELECT MONTH(A)+1,B, SUM(F) WHERE A IS NOT NULL GROUP BY MONTH(A)+1,B LABEL MONTH(A)+1 'MONTH', SUM(F)'TOTAL'",1)
Month Wise Summary in Google Sheets - Example

We have created a month-wise summary report using QUERY in Google Sheets.

COUNT, AVERAGE, MIN, and MAX in Month Wise Summary in Google Sheets

When you create a month-wise summary report using the QUERY function, you can use aggregation functions other than the SUM function.

For example, you can use the QUERY AVG, COUNT, MAX, and MIN aggregation functions to calculate the average, count, maximum, and minimum values in a group of data.

For example, to create a monthly average sales summary of products, you could use the following formula:

=QUERY(A1:F,"SELECT MONTH(A)+1,B, AVG(F) WHERE A IS NOT NULL GROUP BY MONTH(A)+1,B LABEL MONTH(A)+1 'MONTH', AVG(F)'TOTAL'",1)

Conclusion

When replacing QUERY data with imported data, such as an IMPORTRANGE formula, you must replace column identifiers in the query statement with column numbers.

You would use Col1 to represent the first column in the imported data, Col2 to the second column, and so forth.

Here is an example formula:

=QUERY(IMPORTRANGE("URL","Sheet1!A1:F"),"SELECT MONTH(Col1)+1,Col2, AVG(Col6) WHERE Col1 IS NOT NULL GROUP BY MONTH(Col1)+1,Col2 LABEL MONTH(Col1)+1 'MONTH', AVG(Col6)'TOTAL'",1)

We have created a month-wise summary report that uses month numbers for grouping. If you would like to use month names instead, you can use the EOMONTH function in the QUERY data.

You may find these tutorials useful:

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.

Excel Word Count: Beyond SUBSTITUTE

You might want to count the number of words in a cell in Excel...

Sum by Quarter in Excel: New and Efficient Techniques

Knowing how to sum by quarter is crucial in Excel because quarterly reporting has...

Sum By Month in Excel: New and Efficient Techniques

Suppose you prefer to sum by month in Excel using a formula. In that...

How to Create An In-Cell Progress Bar in Excel

In-cell progress bars in Excel refer to bars that are within a cell, not...

More like this

Count Distinct Values in Google Sheets Pivot Table

There is a built-in function for counting distinct values in a Google Sheets Pivot...

Conditional Formatting for Pivot Tables in Google Sheets

Do you know how to dynamically restrict conditional formatting within the Pivot Table area...

XLOOKUP in Merged Cells in Google Sheets

In Google Sheets, merging cells is not a good idea if you intend to...

6 COMMENTS

  1. Hi Prashant,

    Thank you for your help. I am still facing a bit of a mystery with my query. When I add filtering on dates, everything goes wrong.

    Here is my query with date filtering:

    "Select Col1, sum(Col2) where
    Col3 matches true
    and Col1 < date '"&text(eomonth(B5, 0),"yyyy-mm-dd")&"'
    group by Col1
    label sum(Col2) ''")

    where B5 contains 2023-07-12

    I am expecting the result to be the following:

    2023-06-30 -1000
    Instead, it gives me an error saying the request ended with no results.

    Any idea how to solve this?

    Thank you,

  2. Prashant,

    Thanks for your post. It has helped me summarise my data by month. There is a slight challenge. If the data ranges from May 2018 to Jul 2019 then it does not show the months as 13, 14, 15, etc. It combines the data for May 2018 with May 2019. Can you please provide a solution for this?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.