<?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: WeekYear gives wrong value when set ReferenceDay in Archived Groups</title>
    <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56835#M3810</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ralf, I agree that Qlik should fix their HELP pages and make all calendar functions regard the system variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With regard to the proposed fix, I believe this code won't return the correct WeekYear e.g. for 2006-01-01 or for Week 53 /2008 in your sample setting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; If(Week(TempDate)=1, Year(WeekEnd(TempDate)), Year(Weekstart(TempDate))) as WeekYearCorrected2, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Apr 2018 13:36:24 GMT</pubDate>
    <dc:creator>swuehl</dc:creator>
    <dc:date>2018-04-05T13:36:24Z</dc:date>
    <item>
      <title>WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56830#M3805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when I use these calendar settings:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15228746646307360" jivemacro_uid="_15228746646307360" modifiedtitle="true"&gt;
&lt;P&gt;SET FirstWeekDay=6; // Begin of week is Sunday&lt;/P&gt;
&lt;P&gt;SET ReferenceDay=5; // 1st week of year if 5 days in January&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the WeekYear() function gives the wrong year:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="WeekYearIssue.png" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/198514_WeekYearIssue.png" style="height: 403px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;Calendar Script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15228747859587815" jivemacro_uid="_15228747859587815" modifiedtitle="true"&gt;
&lt;P&gt;[MasterCalendar]:&lt;/P&gt;
&lt;P&gt;LOAD &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date(TempDate) AS BookingDate, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; week(TempDate) As Week,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WeekYear(TempDate) as WeekYear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(Week(TempDate)=1 AND Num(Month(TempDate))=12, Year(TempDate)+1, WeekYear(TempDate)) as WeekYearCorrected,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year(TempDate) As Year, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month(TempDate) As Moth,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month(MakeDate(WeekYear(TempDate), If(Week(TempDate)=1, 1, If(Week(TempDate)&amp;gt;=52, 12, Month(TempDate))), 1)) As WeekMonth,&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Day(TempDate) As Day, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WeekDay(TempDate) as Weekday,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date(TempDate, 'WWWW') as WeekDayLong&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;//=== Generate a temp table of dates === &lt;/P&gt;
&lt;P&gt;LOAD &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date(mindate + IterNo()) AS TempDate,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxdate // Used in InYearToDate() above, but not kept &lt;/P&gt;
&lt;P&gt;WHILE mindate + IterNo() &amp;lt;= maxdate;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;// Test case&lt;/P&gt;
&lt;P&gt;LOAD MakeDate(2007,11,30) as mindate,&lt;/P&gt;
&lt;P&gt;MakeDate(2009,1,31) as maxdate&lt;/P&gt;
&lt;P&gt;AutoGenerate(1);&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also added a workaround (field WeekYearCorrected) but would be better if this got fixed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ralf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2025 14:48:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56830#M3805</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2025-07-23T14:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56831#M3806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;A href="https://help.qlik.com/en-US/sense/February2018/Subsystems/Hub/Content/Scripting/DateAndTimeFunctions/weekyear.htm"&gt;official documentation&lt;/A&gt; states that the "function returns the year to which the week number belongs according to &lt;A href="https://en.wikipedia.org/wiki/ISO_8601"&gt;ISO 8601&lt;/A&gt;". ISO 8601 has Monday fixed as the first day of week, as far as I can tell. Sorry...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 10:32:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56831#M3806</guid>
      <dc:creator>sgrubic</dc:creator>
      <dc:date>2018-04-05T10:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56832#M3807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's right that WeekYear works according to ISO 8601, but this is very doubtful since then a variable ReferenceDay should not exist at all, or alternativly a WeekYearNonISO function should exist to have a consistent &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/alert.png" /&gt; calendar behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2nd, you're wrong with the Monday. ISO 8601 says first Thursday in January defines the first week.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 10:49:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56832#M3807</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2018-04-05T10:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56833#M3808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To make it more clear, all date or calendar functions should work according to the settings (FirstWeekDay, ReferenceDay, etc.) .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Who is helped when single functions work different, like WeekYear according to ISO.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 11:24:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56833#M3808</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2018-04-05T11:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56834#M3809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, I meant to say that Monday is always the first day of (any) week; overriding your statement:&lt;/P&gt;&lt;OL class="dp-c" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; color: #5c5c5c; margin: 0 0 1px 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;SET FirstWeekDay=6; // Begin of week is Sunday&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But yes, I completely agree that the behavior isn't consistent, and it (of course) should be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Moreover, I just figured out that the &lt;A href="https://help.qlik.com/en-US/sense/February2018/Subsystems/Hub/Content/Scripting/DateAndTimeFunctions/week.htm"&gt;official help for Week function&lt;/A&gt;‌ also claims that it works according to ISO 8601, but it behaves differently (as observed in your screenshot). And when I say "differently", I mean "consistent with other functions, except for WeekYear". &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All in all, I think this should be filed as a bug.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 12:29:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56834#M3809</guid>
      <dc:creator>sgrubic</dc:creator>
      <dc:date>2018-04-05T12:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56835#M3810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ralf, I agree that Qlik should fix their HELP pages and make all calendar functions regard the system variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With regard to the proposed fix, I believe this code won't return the correct WeekYear e.g. for 2006-01-01 or for Week 53 /2008 in your sample setting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; If(Week(TempDate)=1, Year(WeekEnd(TempDate)), Year(Weekstart(TempDate))) as WeekYearCorrected2, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 13:36:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56835#M3810</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2018-04-05T13:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: WeekYear gives wrong value when set ReferenceDay</title>
      <link>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56836#M3811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Stefan! This is much better..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 13:51:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Archived-Groups/WeekYear-gives-wrong-value-when-set-ReferenceDay/m-p/56836#M3811</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2018-04-05T13:51:40Z</dc:date>
    </item>
  </channel>
</rss>

