<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49398#M28096</link>
    <description>&lt;P&gt;I just noticed that the calculation appears to break down at the end of the year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example for this year, 9/30/17 is the beginning of week 41.&amp;nbsp; All other weeks starting on Saturday properly increment up through 12/30/17 wich is the begining of week 54.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason, rather than continuing with week 54 for the next 6 days, or skipping week 54 and starting week 1, JMP labels Saturday 12/30 as week 54, and Sunday 12/31 as the first day of Week 1 in 2018.&amp;nbsp; Looks like a flaw, since weeks should not start on two different days over a data set?&lt;/P&gt;&lt;P&gt;I will need to add an if loop to change all week 54 data to week 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2018 21:33:49 GMT</pubDate>
    <dc:creator>JensRiege</dc:creator>
    <dc:date>2018-01-08T21:33:49Z</dc:date>
    <item>
      <title>Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49379#M28078</link>
      <description>&lt;P&gt;My company uses a fiscal calendar where the weeks start on Saturdays. According the the JSL WEEKOFYEAR() function we have two options: Rule 1 and 2 for weeks that start on Sundays, and Rule 3, for weeks that start on Mondays.&lt;/P&gt;&lt;P&gt;Has anyone created a JMP script to calculate the week of the year for weeks that start on a day other than Sunday or Monday?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 15:53:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49379#M28078</guid>
      <dc:creator>JensRiege</dc:creator>
      <dc:date>2018-01-08T15:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49381#M28080</link>
      <description>&lt;P&gt;If you add a day to the calculation you will get what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
Week Of Year( Today() + In Days( 1 ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jan 2018 16:00:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49381#M28080</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-08T16:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49394#M28092</link>
      <description>Thank you txnelson!&lt;BR /&gt;I like your answer better than the one I came up with. Your answer is more efficient...&lt;BR /&gt;&lt;BR /&gt;I have a table of dates, and used three separate formulas to add a day to the fiscal Week only if the day is Saturday:&lt;BR /&gt;&lt;BR /&gt;In one column, Fiscal_Week, I use the WeekofYear() function: Week Of Year(:TIMESTAMP)&lt;BR /&gt;In the next column, DayOfWeek, I determine which day of the week it is: Day Of Week(:ET_TIME)&lt;BR /&gt;And in the third column, CompanyFiscalWeek I was able to get the correct value using the formula:&lt;BR /&gt;If (:Day of Week == 7, :Fiscal_Week + 1, :Fiscal_Week )&lt;BR /&gt;&lt;BR /&gt;I'll use your solution instead. Thanks !&lt;BR /&gt;Jens</description>
      <pubDate>Mon, 08 Jan 2018 21:04:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49394#M28092</guid>
      <dc:creator>JensRiege</dc:creator>
      <dc:date>2018-01-08T21:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49398#M28096</link>
      <description>&lt;P&gt;I just noticed that the calculation appears to break down at the end of the year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example for this year, 9/30/17 is the beginning of week 41.&amp;nbsp; All other weeks starting on Saturday properly increment up through 12/30/17 wich is the begining of week 54.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason, rather than continuing with week 54 for the next 6 days, or skipping week 54 and starting week 1, JMP labels Saturday 12/30 as week 54, and Sunday 12/31 as the first day of Week 1 in 2018.&amp;nbsp; Looks like a flaw, since weeks should not start on two different days over a data set?&lt;/P&gt;&lt;P&gt;I will need to add an if loop to change all week 54 data to week 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 21:33:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49398#M28096</guid>
      <dc:creator>JensRiege</dc:creator>
      <dc:date>2018-01-08T21:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49402#M28098</link>
      <description>&lt;P&gt;Good catch, here is a simple solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
testdate = Date MDY( 12, 31, 2017 );
Week Of Year( testdate + If( Year( testdate ) == Year( testdate + In Days( 1 ) ), In Days( 1 ), 0 ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2018 22:27:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/49402#M28098</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-08T22:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/64769#M34258</link>
      <description>&lt;P&gt;Sorry the delay in replying. Your solution works well. Thank you.&lt;/P&gt;&lt;P&gt;Just to make sure that the solution is clear,&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Good catch, here is a simple solution&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
testdate = Date MDY( 12, 31, 2017 );
Week Of Year( testdate + If( Year( testdate ) == Year( testdate + In Days( 1 ) ), In Days( 1 ), 0 ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;by adding 1 day to testdate with the In Days(1) function, Sunday = 2, Monday = 3, ... Friday = 7 and Saturday wraps around to be 1 again since there is no 8th day in a week.&lt;/P&gt;&lt;P&gt;I also like that you can define a variable within a formula. Very helpful!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 00:51:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/64769#M34258</guid>
      <dc:creator>JensRiege</dc:creator>
      <dc:date>2018-07-30T00:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating WEEKOFYEAR() for weeks that start on a day other than Sunday or Monday</title>
      <link>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/714426#M89773</link>
      <description>&lt;P&gt;Besides different days for "first of week", it's also a bit surprising, how Week of Year is calculated in general.&lt;/P&gt;&lt;P&gt;Especially when comparing "Week of Year" and "Year Week" (from the new formula context menu).&lt;BR /&gt;In 2023, Rule #3 was more than 1 week delayed compared to Rule #1:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1704826045502.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60233iF7E89008049DA79D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1704826045502.png" alt="hogi_1-1704826045502.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_2-1704826293964.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/60234iC8D8E41DC3327880/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_2-1704826293964.png" alt="hogi_2-1704826293964.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "Week",
	Add Rows( 30 ),
	New Column( "date",
		Format( "m/d/y", 12 ),
		Formula( Date MDY( 1, 1, 2023 ) + (Row() - 11) * (24 * 3600) )
	),
	New Column( "\!"Year Week\!"",
		Character,
		"Nominal",
		Formula(
			Local(
				{w = Week Of Year( :date, 3 ), y = Year( :date ), m = Month( :date )
				},
				If( Is Missing( :date ),
					"",
					Char( If( m / w &amp;gt;= 12, y + 1, w / m &amp;gt;= 52, y - 1, y ) ) ||
					If( w &amp;gt;= 10, "W", "W0" ) || Char( w )
				)
			)
		)
	),
	New Column( "Week of Year, rule1",
		Formula( Week Of Year( :date ) )
	),
	New Column( "Week of Year, rule3",
		Format( "Best", 12 ),
		Formula( Week Of Year( :date, 3 ) ),
		Color Cells( {32, {19, 20, 21, 22, 23, 24, 25}} )
	),
	New Column( "day",
		Formula( Day Of Week( :date ) ),
		Value Labels( {1 = "Sun", 2 = "Mon"} ),
		Use Value Labels( 1 )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 18:51:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Calculating-WEEKOFYEAR-for-weeks-that-start-on-a-day-other-than/m-p/714426#M89773</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-01-09T18:51:47Z</dc:date>
    </item>
  </channel>
</rss>

