+ Reply to Thread
Results 1 to 6 of 6

How does the following formula set the month based on week number?

  1. #1
    Forum Contributor
    Join Date
    05-30-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    107

    How does the following formula set the month based on week number?

    I am using the following formula to decide which month a certain week belongs to:

    Please Login or Register  to view this content.
    But unfortunately I must say that I do not understand the formula fully. But I think it chooses month based on in which month the wednesday of the week is. Is that correct?

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: How does the following formula set the month based on week number?

    Quote Originally Posted by OldManExcellor View Post
    .....I think it chooses month based on in which month the wednesday of the week is. Is that correct?
    It's difficult to say - it depends how currWeek is defined - are they ISO weeks or something else?

    Also it doesn't make sense to me to have the second DATE function as this

    =DATE(currWeek;1;3)

    Are you sure that should be currWeek? As the first argument of DATE function it's more likely that should be currYear
    Audere est facere

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: How does the following formula set the month based on week number?

    I assume these must be ISO weeks

    ISO weeks are defined such that week 1 starts on the first Monday on or after 29th December......so that would make the first Wednesday fall between 31st Dec and 6th Jan, which fits with what your formula does (if you change the second instance of currWeek to currYear, as suggested)

    So this part

    =DATE(currYear;1;currWeek*7)-WEEKDAY(DATE(currYear;1;3))

    when currWeek = 1 will give you the first Wednesday on or after 31st December....and then as you increment currWeek throughout the year it will give you each subsequent Wednesday, so yes, you are right, as long as currWeek gives the ISO week number (which can be 53 in some years) you will get the month of the Wednesday of that week.

    This can mean that week 1 will be in Dec (when week 1 starts on Monday 29th December, which will be the case for 2015).

    The way ISO numbers are designed you can only ensure that week 1 will always be in Jan and also week 52/53 in Dec if you use the Thursday to determine the month.

    Note also that if you have Swedish regional settings you could use TEXT function to shorten the formula, although I don't think you'll get the month starting with a capital letter, e.g. with this version

    =TEXT(DATE(currYear;1;currWeek*7)-WEEKDAY(DATE(currYear;1;3));"MMM")
    Last edited by daddylonglegs; 10-03-2014 at 09:15 AM.

  4. #4
    Forum Contributor
    Join Date
    05-30-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2013
    Posts
    107

    Re: How does the following formula set the month based on week number?

    That is a great reply! Thank you very much! I will go by Thursday then! How do I do that? :-)

    I found a similar link here:
    http://www.extendoffice.com/document...ek-number.html

    where the author uses the formula:
    MONTH(DATE(A2,1,B2*7-2)-WEEKDAY(DATE(B2,1,3)))

    so he adds a -2 after B2*7 but otherwise uses the same formula. Any idea why he does this?

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: How does the following formula set the month based on week number?

    -2 will give you the start of the week (i.e. the Monday), so -1 will give you the Tuesday, not adding or subtracting anything (like your formula) gives the Wednesday so Thursday is +1

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: How does the following formula set the month based on week number?

    ....also if you are just deriving currYear and currWeek from the current date then there's really no need to use those to find out the "month" of the current week, you can do that directly from today's date, e.g. this formula

    =TEXT(TODAY()-WEEKDAY(TODAY();3)+3;"MMM")

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. formula that generates month and week number from date
    By ea223 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-03-2013, 07:19 AM
  2. [SOLVED] Date Formula to Return Week Number in Current Month based on Reporting Period
    By jeversf in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-25-2013, 12:10 PM
  3. Formula for Week number within a fiscal month
    By GerryT in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-18-2012, 08:14 PM
  4. Need a formula to show the week number of the month
    By ROBERTGRAHAM01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-29-2008, 06:44 AM
  5. Replies: 1
    Last Post: 03-10-2006, 05:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1