<?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: Loop through dates in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340315#M125642</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I think I just figured it out.&amp;nbsp; You can use this in your load and it works.&amp;nbsp; Don't ask me what it is doing or tell me how ugly it is, because I pieced together about 5 different answers to get here, so I'm going with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #0000ff; font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,4) = 0 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,100) &amp;lt;&amp;gt; 0 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;or&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,400) = 0, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; - &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;YearStart&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) + &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;MakeDate&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1) +2), &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; - &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;YearStart&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) + &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;MakeDate&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1) +1)) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;same_day_ly&lt;/SPAN&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Aug 2012 20:52:10 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-08-29T20:52:10Z</dc:date>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340301#M125628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, so I've created these variables based on max date. How would I change the vShift variable to loop through all of my dates? I want to set my dates back for leap years and compare this years day, to last years day.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMaxDate1 = Date('$(vMaxDate)');&lt;/P&gt;&lt;P&gt;LET vMaxDate_Num = num('$(vMaxDate)');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Max = weekday('$(vMaxDate)');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Max_Num = num(weekday('$(vMaxDate)'));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vShift = &lt;/P&gt;&lt;P&gt;IF (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(mod(year('$(vMaxDate)'), 4) = 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;($(vMaxDate_Num) &amp;gt;= num(makedate(year('$(vMaxDate)'), 2, 29))))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(mod(year('$(vMaxDate)'), 4) = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;($(vMaxDate_Num) &amp;lt; num(makedate(year('$(vMaxDate)'), 3, 1))))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;, 2, 1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMinDate = addmonths('$(vMaxDate)', -12, -1);&lt;/P&gt;&lt;P&gt;LET vMinDate_Num = num('$(vMinDate)');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Min = weekday('$(vMinDate)');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Min_Num = num(weekday('$(vMinDate)'));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMinDate_Num_Adjusted = $(vMinDate_Num) + $(vShift);&lt;/P&gt;&lt;P&gt;LET vMinDate_Adjusted = date('$(vMinDate_Num_Adjusted)', 'MM/DD/YYYY');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Min_Adjusted = weekday('$(vMinDate_Adjusted)');&lt;/P&gt;&lt;P&gt;LET vDayOfWeek_Min_Num_Adjusted = num(weekday('$(vMinDate_Adjusted)'));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 May 2012 19:06:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340301#M125628</guid>
      <dc:creator />
      <dc:date>2012-05-07T19:06:53Z</dc:date>
    </item>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340302#M125629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears that your vMinDate_Num_Adjusted calculation always* gives you the date 364 days ago. Why not use &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMinDate_Num_Adjusted = Date(vMaxDate - 364);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Avoid any leap year determination in your scripts since leap years are not always every fourth year. &lt;A href="http://en.wikipedia.org/wiki/Leap_year#Algorithm"&gt;http://en.wikipedia.org/wiki/Leap_year#Algorithm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 01:26:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340302#M125629</guid>
      <dc:creator />
      <dc:date>2012-05-08T01:26:05Z</dc:date>
    </item>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340303#M125630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All QlikView functions use the correct Gregorian leap year algorithm. So, just as vhuynh says - avoid any leap year calculation. You do not need any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to set the date back one year, use the AddYears function: &lt;/P&gt;&lt;P&gt;Let vMinDate_Num_Adjusted = AddYears(vMaxDate, -1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to compare this year's day n with last years day n, then last year's day n is found through: &lt;/P&gt;&lt;P&gt;Let vMinDate_Num_Adjusted = vMaxDate - MakeDate(Year(vMaxDate)) + MakeDate(Year(vMaxDate)-1) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 06:46:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340303#M125630</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2012-05-08T06:46:15Z</dc:date>
    </item>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340304#M125631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, I didn't know about the gregorian leap year algorithm. So that helps, but your calculation still doesn't come up with the right day. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Saturday 3/31/2012 should be compared to Saturday 4/2/2011. But your calculation says 4/1/2011.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I want to do this calculation over a period of time. Say take each day and minus it by its previous day to gets its delta. This variable only allows me to grab the maxdate. What am I missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 13:09:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340304#M125631</guid>
      <dc:creator />
      <dc:date>2012-05-08T13:09:03Z</dc:date>
    </item>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340305#M125632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you want to do this on table data, you should define your formulas inside a Load statement. For instance, your date calculation should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Date(Date - YearStart(Date) + MakeDate(Year(Date)-1) +1) as OneYearAgo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further, if you want to compare one record with the previous to calculate a diff, then you could use the peek() function in the script, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Amount-peek(Amount) as Diff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or you can use the above() function in a chart, e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Sum(Amount) - Above(Sum(Amount)) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 May 2012 14:51:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340305#M125632</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2012-05-08T14:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340306#M125633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, i will attempt to build that in. So this is my expression. I'm getting the correct numbers for the LHS. But when I try to compare against last years day, it is comparing the same date, not day. I've attached the view of what my client is attempting to do. Can I change the As of Date by 1 or 2, depending on leap year?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=sum({$&amp;lt;"Date Type"={'Rolling 28 Days'},"As of Date"={"&amp;gt;=$(=addmonths(max("As of Date")+1,-12)) &amp;lt;=$(=max("As of Date"))"}&amp;gt;}Cnt)-&lt;/P&gt;&lt;P&gt;sum({$&amp;lt;"Date Type"={'Rolling 28 Days'},"As of Date"={"&amp;gt;=$(=addmonths(max("As of Date")+1,-24)) &amp;lt;=$(=addmonths(max("As of Date"),-12))"}&amp;gt;}Cnt)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 14:48:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340306#M125633</guid>
      <dc:creator />
      <dc:date>2012-05-10T14:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340307#M125634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can add or subtract any way you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the formula above for "OneYearAgo" already compensates for leap years. It calculates the day number of the year using "Date - YearStart(Date)" and then adds the YearStart of previous year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 15:20:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340307#M125634</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2012-05-10T15:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340308#M125635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Right, but how do I find the difference between the two?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you build me a quick sample? I've attached my application that I'm working in if it helps at all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 16:04:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340308#M125635</guid>
      <dc:creator />
      <dc:date>2012-05-10T16:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340309#M125636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this roughly what you want?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Pivot.png" class="jive-image-thumbnail jive-image" onclick="" src="https://community.qlik.com/legacyfs/online/14084_Pivot.png" width="450" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 May 2012 09:31:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340309#M125636</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2012-05-11T09:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340310#M125637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure, its hard to distinguish what the Date of the DayNumberofYears is. My gut feeling says no since, DayNumberofYear for 1/6/2011 should be 6, not 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remember I'm just trying to compare &lt;STRONG style="background-color: #ffffff; color: #636363; font-family: Arial; font-size: 12px;"&gt;1/6/&lt;/STRONG&gt;&lt;SPAN style="background-color: #ffffff; color: #636363; font-family: Arial; font-size: 12px;"&gt;2011 to 1/5/2012.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 13:48:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340310#M125637</guid>
      <dc:creator />
      <dc:date>2012-05-15T13:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340311#M125638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All you need to do then is to create your own field DayNumberOfYear. Don't use the function. Instead, you can use, e.g. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Date - YearStart(Date) + 1 + Year(Today()) - Year(Date) as DayNumberOfYear&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The two last terms will shift the dayNo by 1 for last year, two for the year before that etc. Then you will compare 1/6/2011 with 1/5/2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HIC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 21:55:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340311#M125638</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2012-05-15T21:55:36Z</dc:date>
    </item>
    <item>
      <title>Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340312#M125639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Becareful about leap year (like this year) which will put the dates off again.&lt;/P&gt;&lt;P&gt;Stephen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 May 2012 22:01:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340312#M125639</guid>
      <dc:creator />
      <dc:date>2012-05-15T22:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340313#M125640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay so close. But I'm comparing 1/5/2012 to 1/4/2011.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="ScreenShot707.bmp" class="jive-image-thumbnail jive-image" onclick="" src="https://community.qlik.com/legacyfs/online/14326_ScreenShot707.bmp" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;﻿&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 15:16:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340313#M125640</guid>
      <dc:creator />
      <dc:date>2012-05-16T15:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340314#M125641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you ever get this to work?&amp;nbsp; I tried using both these, and it doesn't seem to be accounting for leap year.&amp;nbsp; For 1/3/2009 (Sat) I am getting 1/4/2008 (Fri) instead of 1/5/2008 (Sat) for both of these.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;AddYears&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;, -1) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;same_day_last_year1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; - &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;YearStart&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) + &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;MakeDate&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1) +1) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;SPAN style="color: #800000; font-size: 8pt;"&gt;same_day_last_year2&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 19:25:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340314#M125641</guid>
      <dc:creator />
      <dc:date>2012-08-29T19:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dates</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340315#M125642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I think I just figured it out.&amp;nbsp; You can use this in your load and it works.&amp;nbsp; Don't ask me what it is doing or tell me how ugly it is, because I pieced together about 5 different answers to get here, so I'm going with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style=": ; color: #0000ff; font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,4) = 0 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,100) &amp;lt;&amp;gt; 0 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;or&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;mod&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1,400) = 0, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; - &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;YearStart&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) + &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;MakeDate&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1) +2), &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; - &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;YearStart&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) + &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;MakeDate&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Year&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Datefield&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)-1) +1)) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;same_day_ly&lt;/SPAN&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 20:52:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-through-dates/m-p/340315#M125642</guid>
      <dc:creator />
      <dc:date>2012-08-29T20:52:10Z</dc:date>
    </item>
  </channel>
</rss>

