Sum Current Month Data Using Query Function in Google Sheets

Published on

We can make the use of month(), year(), and now() functions to sum current month data using Query in Google Sheets. The use of these scalar functions in Query is not much tough compared to the date criterion use in Query.

Honestly, the use of date criterion in Query is tough to remember. I am not an exception to this. When I want to use any date as Query criterion, I always end up referring to my own two old tutorials (links below).

  1. How to Use Date Criteria in Query Function in Google Sheets.
  2. Examples to the Use of Literals in Query in Google Sheets.

The first tutorial is purely on Query date criterion use whereas the second tutorial contains more details like the use of DateTime as well as other criteria.

If you want, you can bookmark these tutorials on your browser for your future reference.

Right now, going through the above tutorials is not at must as sum by current month in Query is quite easy to understand.

Coming back to our topic, let’s first learn how to filter by month in Google Sheets Query. After that, we can easily learn how to sum the current month’s records using the Query function in Google Sheets.

Sample Data: Please note that the current month at the time of writing this post is September and the current year is 2019.

Google Sheets - Sum Current Month Data Using Query Function

The Role of Year(), Month() and Now() Scalar Functions to Filter Records Fall in Current Month

To filter any particular month’s data, you can use the month() scalar function as below in Google Sheets.

=query(B1:D,"Select * where month(B)=8")

This Query will filter the records that fall in the month of September.

I have used the number 8 to represent the month of September instead of using month number 9. Because in Query, the month number is starting from 0 and ending in 11, not from 1 to 12. So obviously 8 will represent September, not August.

To dynamically filter the current month using Query, we can replace the month number 8 with month(now()).

=query(B1:D,"Select * where month(B)=month(now())")

Here you will face one obstacle. Assume the date in cell B16 is 8/9/20 instead of 8/9/19 (both in DD/MM/YY format).

The above formula will still include this record in the filtered output as it won’t consider the year. To sort out this problem, we can additionally use the Year() scalar function.

The final Query formula to filter rows that fall in the current month will be as follows.

=query(B1:D,"Select * where month(B)=month(now()) and year(B)=year(now())")

Query to Sum Current Month Records in Google Sheets

You have learned to filter the current month’s data using Query. Then to Sum, use the following Query.

Just replace the * by Sum(D).

=query(B1:D,"Select Sum(D) where month(B)=month(now()) and year(B)=year(now())")

You May Like: How to Sum, Avg, Count, Max, and Min in Google Sheets Query.

Conditionally Sum Current Month Data Using Query in Google Sheets

In Query, it’s pretty easy to include several criteria. For example, I want to sum the current month sale of the item “Orange”. The pertaining Query formula will be as follows.

Formula to Sum Current Month’s Records Plus One Additional Criterion:

=query(B1:D,"Select Sum(D) where C='Orange' and month(B)=month(now()) and year(B)=year(now())")

Want one more criterion in Query current month sum?

Formula to Sum Current Month’s Records Plus Two More Criteria:

Here the formula sums the sales in column D based on the below conditions.

  • Date = Current Month
  • Year = Current Year
  • Item = Orange or Mango

Formula:

=query(B1:D,"Select Sum(D) where (C='Orange' or C='Mango') and (month(B)=month(now()) and year(B)=year(now()))")

That’s all. Any doubt regarding the formula used? Please do post in the comments. 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.

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

How to Create a Searchable Table in Excel Using the FILTER Function

Finding specific records, or rows containing the required information, is straightforward in Excel using...

Time Sequences in Excel by Minute, Hour, or Second Increments

Creating time sequences, whether by hour, minute, or second increments in Excel, can be...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

2 COMMENTS

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.