# Using a Week Number as One Criterion in a Formula

by Allen Wyatt
(last updated May 1, 2019)

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:

```http://excelribbon.tips.net/T007804
http://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, and Excel in Office 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

Transferring Fonts

Do you want to transfer fonts from one computer system to another? It is relatively easy to do, but there is one ...

Discover More

Selective Summing

If you want to add up the contents of a range of cells based on what is contained in a different range of cells, you need ...

Discover More

Pasting a Comment into Your Document

When developing a document, you may end up with all sorts of comments that you need to deal with. One common task is to ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

##### More ExcelTips (ribbon)

Returning Blanks or Asterisks from a Lookup

Want to return more than a value when doing a lookup? Here are a couple of ways to do it by adding an IF clause to your ...

Discover More

Returning the Left-most Characters

When working with text in a formula, you may need to extract the left-most characters from a string of text or from a ...

Discover More

Establishing a FLOOR and CEILING

Excel includes a surprising number of functions you can use to round your data. Two such functions are FLOOR and CEILING, ...

Discover More
##### Subscribe

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

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}] 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 five more than 4?

2015-02-28 06:10:04

Michael (Micky) Avidan

@VIKRAM,
1( Please emphasize whether, as per your criteria, you want one single result of: 377500 or two separate results: 337500 in one cells and 40000 in another ?
2) What version of "Excel" are you using ?
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL

2015-02-27 06:37:55

VIKRAM

SIR PLEASE According to the date of the calculation are the ones for me..
EX : 14/03/2014 IPPA ASHANNA 10000
18/03/2014 ENUGU MUTHYAM REDDY 10000
19/03/2014 VANNELA LINGAM 40000
20/03/2014 KUNCHAM GANESH 15000
21/03/2014 KOGURI GANGAMANI 8000
24/03/2014 MUSKU NARAYANA 25000
24/03/2014 KALLEM LINGAREDDY 20000
24/03/2014 PUPPALA DEVANNA 80000
24/03/2014 NANGU AMRUTHA 200000
25/03/2014 INDRALA RAJESHAM 20000
25/03/2014 GOGULA BUGGA RAMULU 20000
26/03/2014 NANGU AMRUTHA 100000
27/03/2014 GUGLAVATH SANTHA 10000
28/03/2014 MAMIDI THUKKANNA 10000
29/03/2014 KALLEM BUCHILINGU 10000
29/03/2014 OLLEPU GANGU 5000
I NEED 24/3/2014 5 CELLS TOTAL AMOUNT
AND 28/03/2014 2 CELLS TOTAL AMOUNT AT A TIME.
IF ANY FORMULA PLEASE SAY THE FORMULA,,

2014-02-18 11:13:17

Mathew

You can also use the indirect formula to determine exactly what weeks to sum. Doing it this way would allow you to sum say weeks 3-12, or whatever you want.

For example, I use this for months, and I sum the current month, the current quarter, and year to date.

2014-02-18 10:11:43

Bryan

The real reason you have to have the helper columns is because WEEKNUM doesn't work in arrays. If it did, you could use an array-entered SUM formula or a SUMPRODUCT formula.

@Lisa: It would be a lot of headache, but you'd probably be better off in the long run normalizing your data. If you just had three columns (ID, Date, and Sales), it would be really easy to find what you want, by using formulas like the one in Allen's tip.

That being said, you *can* do what you want, without rearranging the data. I'm assuming your data is in cells J19:P26, with the dates in cells J18:P18, and that you want to sum everything from the first column (J) through a date available in cell J30. The formula would be: "=SUM(INDEX(J19:J25,0):INDEX(J19:P25,0,MATCH(J30,J18:P18,0)))". This works by virtue of the fact that using a 0 for Row Number in an INDEX function returns an array for the whole column, and that you can use INDEX as a cell reference.

@Surendera: have you tried a pivot table?

2014-02-16 07:35:27

Surendera M. Bhanot

I have dates randomly placed in Column 'A' and the values of membership fee and donations in column 'F' and 'G'. Excel sheet is A1:B2772. How can I get date wise sum of the valus both for Membership fee and Donations?

I

2014-02-15 10:33:48

Lisa D

What if your dates are running horizontally in a row across the top, is there a horizontally oriented version of this formula?

I have a column containing 100s of item ID numbers and their weekly sales for multiple years in the columns next to each SKU. I want to be able to total YTD sales # based on current week. Is there any way to do this using this formula, or do you have an alternative suggestion? Thank you!

##### 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.