Using a Week Number as One Criterion in a Formula

Written by Allen Wyatt (last updated December 7, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365


2

Dave is trying to create a SUMIFS formula that uses the year as one criterion and the week number as another criterion. This will allow him, for instance, to sum all the values from a particular week in a previous year. The week number criterion needs to be based on whatever week number the current date is within. Thus, if today is within week 3, the formula needs to include weeks 1, 2, and 3 from whatever year he specifies. Dave is sure there is a way to do this, but he can't figure out the right way to express it in SUMIFS.

Using the SUMIFS worksheet function, it is important to understand exactly what the function needs as parameters. When working with two criteria (as Dave wants to do—year and week number), the syntax of the formula based on SUMIFS would look like this:

=SUMIFS(values_to_sum, years_to_compare, year_criterion,
weeks_to_compare, week_criterion)

In Dave's description, what he has is a series of dates and a series of values related to those dates. The values_to_sum parameter is obviously from those values Dave has, but the years_to_compare and weeks_to_compare don't exist in his data. Thus, they must be created in helper columns.

Let's assume that column A contains Dave's original dates and column B contains the values associated with those dates. In column C you can create the first helper column, using this formula in cell C2:

=YEAR(A2)

This assumes that row 1 contains headings for your data columns. The formula for the second helper column is placed in cell D2:

=WEEKNUM(A2)

Copy these formulas down so that there is an associated year and week number for each date that appears in column A. With these helper columns in place, you have all the data pieces necessary to work with the SUMIFS function described earlier. What you still don't have is an indicator of which year you want to extract from the values. This is easily remedied by placing a year into cell F2. Now the requested formula would appear as follows:

=SUMIFS(B:B,C:C,F2,D:D,"<="&WEEKNUM(TODAY()))

If you compare this formula to the syntax example provided earlier, you'll note that you have the values_to_sum (B:B), the years_to_compare (C:C), the year_criterion (F2), the weeks_to_compare (D:D), and finally the week_criterion. It is this last element which needs to be explained a bit; it looks like this:

"<="&WEEKNUM(TODAY())

Since the WEEKNUM function returns whatever week number is appropriate for (in this case) today's date, it may return something like "7". Thus, the week_criterion ends up looking like this:

"<=7"

This means that SUMIFS will only consider those week numbers in the data that are less than or equal to 7.

You might wonder if you can get rid of the helper columns. You cannot do so with SUMIFS. The reason is because the function expects data ranges upon which to do its comparisons, and those data ranges are calculated as the result of formulas in columns C and D.

As a final caveat to using this formula, you should understand precisely how you want to calculate your week number. In the examples in this tip, the simplest version of the WEEKNUM function was used, both in column D and in the SUMIFS formula. There are parameters that can be used with WEEKNUM to adjust how it works. In some instances, you might want to calculate an ISO week number instead. More information on WEEKNUM and ISO week numbers can be found in these tips:

https://excelribbon.tips.net/T007804
https://excelribbon.tips.net/T007847

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12964) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Borders to Paragraphs

Want to draw attention to a particular paragraph? A great way to do it is with a border. Word allows you to easily add ...

Discover More

Selecting a Group of Words

Want to select a chunk of text in a document? Perhaps the easiest way to do this involves using the mouse in conjunction ...

Discover More

Changing the MAC Address for a Network Adapter

MAC addresses are used to uniquely identify devices on your network, such as a network adapter. Here's how you can modify ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Using the TRUNC Worksheet Function

Want to chop off everything after a certain point in a number? The TRUNC function can help with this need.

Discover More

Determining the Least Common Multiple

Need to figure out the least common multiple of a range of values? It is a snap when you use the LCM function, described ...

Discover More

Using the UNIQUE Function

The UNIQUE function can be used to evaluate a range and return the unique values in that range. Understanding how the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven less than 7?

2024-12-11 10:16:26

J. Woolley

Given the scenario of my previous comment below, these formulas will also work
    =SUM(--(C:C=F2)*(D:D<=WEEKNUM(TODAY()))*(B:B))
    =SUM(--(E:E)*(B:B))
but they might require a modern version of Excel that supports dynamic arrays.


2024-12-10 16:10:16

J. Woolley

The Tip adds two helper columns with =YEAR(A2) in cell C2 and =WEEKNUM(A2) in cell D2, then copies these formulas down columns C and D to cover all dates in column A. The Tip's formula to sum column B values for the year specified in cell F2 up to and including today's week number is
    =SUMIFS(B:B,C:C,F2,D:D,"<="&WEEKNUM(TODAY()))
Here's another formula that gives the same result
    =SUMPRODUCT(--(C:C=F2)*(D:D<=WEEKNUM(TODAY()))*(B:B))
The two helper columns could be combined into one by putting this formula in cell E2 and copying it down column E as before:
    =AND((YEAR(A2)=F$2),(WEEKNUM(A2)<=WEEKNUM(TODAY())))
Then the following three formulas give the same result as the first two SUM... formulas presented above:
    =SUMIFS(B:B,E:E,TRUE)
    =SUMIF(E:E,TRUE,B:B)
    =SUMPRODUCT(--(E:E)*(B:B))
SUMIFS requires Excel 2007 or later. SUMIF and SUMPRODUCT are in Excel 2003.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.