Get Week Number in Excel & Reset For Every Month
Get Week Number in Excel & Reset For Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 1/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
There are different approaches to creating reports which involve getting the week numbers for each month.
Before jumping in and creating the report, you will have to think about how you’ll handle the cutoff week.
Do you always want to start in week 1 the moment you get to the first of the month?
Do you consider the last days of January and the first days in February to all be in week 5?
Take this data set which has the dates from January 1, 2017, to the beginning of the year 2018 as an example:
https://www.xelplus.com/reset-week-number-every-month-excel/ 2/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 3/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
For the sake of demonstration and checking, I have used a Weekday column (A) to show that there is no week count for days that fall on
weekends.
To set this up, equate it to the date and merely change the formatting of the cell.
Cell A5 = B5
https://www.xelplus.com/reset-week-number-every-month-excel/ 4/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 5/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Alternatively, you can right click on the cell and select Format Cells.
In the Type, you can choose however you want the data to be displayed.
In this example, we will use “dddd” to display the weekday (Sunday, Monday, etc).
Other format type are yyyy for year and mmmm for the month.
https://www.xelplus.com/reset-week-number-every-month-excel/ 6/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 7/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Cases
Whichever case you are going with for, the report will decide the approach to count the week number.
Taking the end of January and the beginning of February as an example, where January 31 is on a Tuesday and February 1 falls on a Wednesday:
https://www.xelplus.com/reset-week-number-every-month-excel/ 8/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
In Case 1, it is possible to have a week with only 1 weekday (e.g. if the 1st day of the month falls on a Friday, or if the last day of the month falls
on a Monday).
While Case 2 starts counting the first full week of the month starting on a Monday.
https://www.xelplus.com/reset-week-number-every-month-excel/ 9/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Case 1: Using the WEEKNUM() function to start a new week every 1st of the
month
= WEEKNUM(serial_number, [return_type])
Cell C5 = WEEKNUM(B5)
Drag the formula down to the last row (or double click on the lower right corner of the cell).
You will notice that the values rum from week 1 to 53 and then resets to week 1 when it starts a new year.
However, this does not count the 1st of the month as a new week when it doesn’t fall on a Monday.
In this example, we want February 1 to be counted as week 1 of February instead of week 5 of January.
https://www.xelplus.com/reset-week-number-every-month-excel/ 10/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Whenever a new month is started, the week counter should reset back to 1.
https://www.xelplus.com/reset-week-number-every-month-excel/ 11/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Subtract the current week number with the week number of the 1st of the month and increment it as it goes.
We will be using a combination of the DATE() function to find the serial number of the 1st of a specific date, and the YEAR() MONTH()
functions to find what year and month it should use.
The number 1 is used since we want to find the serial number of the 1st day of that month so that we can eventually find its corresponding week
number.
https://www.xelplus.com/reset-week-number-every-month-excel/ 12/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 13/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
You will again notice that the week now starts counting at 0.
Apply the formula down to the last row and now you have the correct week number for February 1 .
Now all that’s left to do is to not display anything when a date falls on a weekend.
https://www.xelplus.com/reset-week-number-every-month-excel/ 14/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
= WEEKDAY(serial_number, return_type]
(8)
In this case, for simplification, use 2 – Numbers 1 (Monday) through 7 (Sunday), which will return the number 6 and 7 for weekends.
We can then use an IF() statement to check if the value returned is bigger than 5 (Friday).
The week number is now blank when the date falls on a weekend.
https://www.xelplus.com/reset-week-number-every-month-excel/ 15/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
When you inspect the data, you will notice that when the 1st of the month falls on a weekend, the first weekday of that month starts as week #2
and skips week #1:
https://www.xelplus.com/reset-week-number-every-month-excel/ 16/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
This is happening because for the instances where the 1st of the month falls on a Saturday, the formula counts it as part of the 1st week.
https://www.xelplus.com/reset-week-number-every-month-excel/ 17/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
So you should tweak the formula to handle this instance by using another IF() statement.
This will tell the formula not to add 1 if the 1st of the month falls on a Saturday (7).
Cell C5
= IF(WEEKDAY(B5,2)>5,””,WEEKNUM(B5)-
IF(WEEKDAY(DATE(YEAR(B5),MONTH(B5),1)=7, WEEKNUM(DATE(YEAR(B5),MONTH(B5),1)),
WEEKNUM(DATE(YEAR(B5),MONTH(B5), 1)) + 1))
Apply the formula for all the rows and it should now display the correct week numbers.
https://www.xelplus.com/reset-week-number-every-month-excel/ 18/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 19/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Using the WEEKDAY() function to reset the week number to 1 every time the first
Monday of the next month is reached
This is especially helpful so that in instances where the week is split between two months (e.g. January 31 falls on a Tuesday, February 1 on a
Wednesday), you can find the date of last Monday and give all the succeeding weekdays the same week number.
Once you have the same number for all the dates in that week, you can then figure out how to switch that to count from weeks 1 through 5 for
any given month.
Cell D6 = WEEKDAY(B6,3)
While January 8 (Sunday) returns a 6, since you are 6 days away from Monday.
You will notice that it resets back to 0 for the next Monday, January 9.
https://www.xelplus.com/reset-week-number-every-month-excel/ 20/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
These values can be used to correct the days and display the appropriate week number.
Going back to January 2 (Monday), think about what you want to display.
In the first case, you would want to display the day number.
https://www.xelplus.com/reset-week-number-every-month-excel/ 21/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
For January 2, you want it to return a 2 for the entire week, while for the week starting January 9, you want it to return a 9 for the inclusive dates.
The approach will be to get the day associated to the specific date and deduct the weekday shown earlier:
Cell D6 = DAY(B6-WEEKDAY(B6,3))
https://www.xelplus.com/reset-week-number-every-month-excel/ 22/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Up to this point, you will get the same number for each week.
Proceed to using these results and convert them into week number 1 through 5 for each month.
Use the WEEKNUM() formula of a date and use the DAY() argument, but being careful to look at the same month and same year.
For the WEEKNUM() formula, since you will be splitting it up and having DAY() as separate, you should use the DATE() function instead:
Cell D6 = WEEKNUM(DATE(YEAR(B6),1,DAY(B6-WEEKDAY(B6,3))))
In the meantime, fix the month parameter as 1 for the formula to look at January.
You will notice that for weeks that have been split between two months, such as the week containing January 31 (Wednesday) and February 1
(Thursday), the values returned are correct.
https://www.xelplus.com/reset-week-number-every-month-excel/ 24/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
To make the outputs look similar, apply a combination of the IF() and WEEKDAY() functions to hide any results for Saturdays and Sundays.
If the weekday of a date a is greater than 5, which means it is a Saturday or Sunday, then it should display nothing.
https://www.xelplus.com/reset-week-number-every-month-excel/ 25/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
Cell D6 = IF(WEEKDAY(B6,2)>5,””,WEEKNUM(DATE(YEAR(B6),1,DAY(B6-WEEKDAY(B6,3))))
https://www.xelplus.com/reset-week-number-every-month-excel/ 26/27
12/29/22, 3:04 PM Get Week Number in Excel & Reset for Every Month
https://www.xelplus.com/reset-week-number-every-month-excel/ 27/27