<?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 YTD and MTD Counts in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215238#M68718</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Oleg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you explain me how u write Rolling Months in script? Below you can see my Calendar:&lt;/P&gt;&lt;P&gt;LET vDateMin = Num(MakeDate(2008,1,1));&lt;BR /&gt;LET vDateMax = Floor(YearEnd(AddMonths(Today(), 1)));&lt;BR /&gt;LET vDateToday = Num(Today());&lt;BR /&gt;&lt;BR /&gt;TempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(vDateMin) + RowNo() - 1 AS DateNumber,&lt;BR /&gt; Date($(vDateMin) + RowNo()-1) AS TempDate&lt;BR /&gt;AUTOGENERATE 1&lt;BR /&gt;WHILE $(vDateMin)+IterNo()-1&amp;lt;= $(vDateMax);&lt;BR /&gt;&lt;BR /&gt;MasterCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; TempDate AS CalendarDate,&lt;BR /&gt; Day(TempDate) AS CalendarDay,&lt;BR /&gt; Week(TempDate) AS CalendarWeek,&lt;BR /&gt; Weekday(TempDate) AS WeekDay,&lt;BR /&gt; Month(TempDate) AS CalendarMonth,&lt;BR /&gt; Year(TempDate) AS CalendarYear,&lt;BR /&gt; 'Q' &amp;amp; Ceil(Month(TempDate)/3) AS CalendarQuarter,&lt;BR /&gt; Month(TempDate) &amp;amp; '-' &amp;amp; Year(TempDate) AS CalendarMonthAndYear,&lt;BR /&gt; Week (TempDate) &amp;amp; '-'&amp;amp; Year (TempDate) as CalendarWeekAndYear,&lt;BR /&gt; Year2Date(TempDate, 0, 1, $(vToday))*-1 AS CurYTDFlag,&lt;BR /&gt; Year2Date(TempDate,-1, 1, $(vToday))*-1 AS LastYTDFlag,&lt;BR /&gt; YearToDate(TempDate, 0, Ceil(Month(Today())/3) * 3 - 2 )*-1 as CurQTDFlag,&lt;BR /&gt; YearToDate(TempDate, -1, Ceil(Month(Today())/3) * 3 - 2 )*-1 as LastQTDFlag,&lt;BR /&gt; Year2Date(TempDate, 0, Month(Today()))*-1 as CurMTDFlag,&lt;BR /&gt; Year2Date(TempDate, -1, Month(Today()))*-1 as LastMTDFlag&lt;BR /&gt;&lt;BR /&gt;RESIDENT TempCalendar&lt;BR /&gt;ORDER BY TempDate ASC;&lt;/P&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;Have a nice day,&lt;/P&gt;&lt;P&gt;Beata Jablonska&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Feb 2010 12:00:26 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-02-03T12:00:26Z</dc:date>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215232#M68712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having trouble parsing out the appropriate Counts in one of my charts. I have several years of data loaded in and I have two expressions I am trying to create. The first is a count of unique orders MTD and the second is a count of unique orders YTD. Unfortunately I do see how I can get the counts to show up in the same chart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2009 23:15:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215232#M68712</guid>
      <dc:creator />
      <dc:date>2009-10-13T23:15:41Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215233#M68713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are functions like InYearTodate, InMonthTodate, InQuarterTodate, that you can use to validate the condition on the fly:&lt;/P&gt;&lt;H4 style="background-color:#c0c0c0;"&gt;InYearToDate&lt;A id="InYearToDate" name="InYearToDate"&gt;&lt;/A&gt; ( date, basedate , shift [, first_month_of_year = 1] )&lt;/H4&gt;&lt;P&gt;I prefer moving this logic back into the load script and generating flags in my Master Calendar that would already have 1 or 0 for each relevant condition (YTD, MTD, QTD, Rolling 12 months, etc...)&lt;/P&gt;&lt;P&gt;Using the flags, we can simplify our expressions, for example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;YTD Sales = sum( {$&amp;lt;YTDFlag={1}&amp;gt;} Sales)&lt;/P&gt;&lt;P&gt;MTD Sales = sum( {$&amp;lt;MTDFlag={1}&amp;gt;} Sales)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second part of your question is how to count distinct orders. You can always use count(distinct OrderID), however, it's quite a slow and memory-consuming operation. We usually recommend preparing a "counter" field in the table that holds unique values - in your case, Order Header. If you load 1 for each order:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;OrderID,&lt;/P&gt;&lt;P&gt;1 as OrderCount,&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;then your expression is as simple as summarizing the value of the OrderCounter:&lt;/P&gt;&lt;P&gt;YTD Orders = sum( {$&amp;lt;YTDFlag={1}&amp;gt;} OrderCounter)&lt;/P&gt;&lt;P&gt;YTD Orders = sum( {$&amp;lt;MTDFlag={1}&amp;gt;} OrderCounter)&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2009 23:28:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215233#M68713</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2009-10-13T23:28:50Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215234#M68714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is very useful information, thank you. It actually gets me most of the way with my current chart. One little snag I have with applying that concept to another expression in my chart is calculating distinct stores for MTD and YTD sales. Orders and Sales is easy but then within that subset is a smaller group of unique stores. Since some of the stores can have multiple orders I am not sure how best to apply this concept to that scenario.&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2009 00:54:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215234#M68714</guid>
      <dc:creator />
      <dc:date>2009-10-14T00:54:46Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215235#M68715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have a separate table for stores, you can load 1 as a counter there. If you don't - you can create it, just for this purpose:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;Stores:&lt;BR /&gt;load distinct&lt;BR /&gt; StoreNumber,&lt;BR /&gt; 1 as StoreCounter&lt;BR /&gt;resident&lt;BR /&gt; Orders&lt;BR /&gt;;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;The rest is pretty much the same&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2009 02:25:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215235#M68715</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2009-10-14T02:25:58Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215236#M68716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome. That does the trick. Thanks so much.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2009 02:31:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215236#M68716</guid>
      <dc:creator />
      <dc:date>2009-10-14T02:31:39Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215237#M68717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, that actually didn't help unless I am doing something wrong. I created a table of unique stores and match it up to my Order Header. I use the MTDFlag to determine the appropriate matches but it still counts the store twice (whether summing the Count field or counting the storekey) if there are two orders with the same store. So right now I have a count of 11 but it should be 10.&lt;/P&gt;&lt;P&gt;What might I be doing wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2009 03:54:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215237#M68717</guid>
      <dc:creator />
      <dc:date>2009-10-14T03:54:04Z</dc:date>
    </item>
    <item>
      <title>YTD and MTD Counts</title>
      <link>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215238#M68718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Oleg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you explain me how u write Rolling Months in script? Below you can see my Calendar:&lt;/P&gt;&lt;P&gt;LET vDateMin = Num(MakeDate(2008,1,1));&lt;BR /&gt;LET vDateMax = Floor(YearEnd(AddMonths(Today(), 1)));&lt;BR /&gt;LET vDateToday = Num(Today());&lt;BR /&gt;&lt;BR /&gt;TempCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; $(vDateMin) + RowNo() - 1 AS DateNumber,&lt;BR /&gt; Date($(vDateMin) + RowNo()-1) AS TempDate&lt;BR /&gt;AUTOGENERATE 1&lt;BR /&gt;WHILE $(vDateMin)+IterNo()-1&amp;lt;= $(vDateMax);&lt;BR /&gt;&lt;BR /&gt;MasterCalendar:&lt;BR /&gt;LOAD&lt;BR /&gt; TempDate AS CalendarDate,&lt;BR /&gt; Day(TempDate) AS CalendarDay,&lt;BR /&gt; Week(TempDate) AS CalendarWeek,&lt;BR /&gt; Weekday(TempDate) AS WeekDay,&lt;BR /&gt; Month(TempDate) AS CalendarMonth,&lt;BR /&gt; Year(TempDate) AS CalendarYear,&lt;BR /&gt; 'Q' &amp;amp; Ceil(Month(TempDate)/3) AS CalendarQuarter,&lt;BR /&gt; Month(TempDate) &amp;amp; '-' &amp;amp; Year(TempDate) AS CalendarMonthAndYear,&lt;BR /&gt; Week (TempDate) &amp;amp; '-'&amp;amp; Year (TempDate) as CalendarWeekAndYear,&lt;BR /&gt; Year2Date(TempDate, 0, 1, $(vToday))*-1 AS CurYTDFlag,&lt;BR /&gt; Year2Date(TempDate,-1, 1, $(vToday))*-1 AS LastYTDFlag,&lt;BR /&gt; YearToDate(TempDate, 0, Ceil(Month(Today())/3) * 3 - 2 )*-1 as CurQTDFlag,&lt;BR /&gt; YearToDate(TempDate, -1, Ceil(Month(Today())/3) * 3 - 2 )*-1 as LastQTDFlag,&lt;BR /&gt; Year2Date(TempDate, 0, Month(Today()))*-1 as CurMTDFlag,&lt;BR /&gt; Year2Date(TempDate, -1, Month(Today()))*-1 as LastMTDFlag&lt;BR /&gt;&lt;BR /&gt;RESIDENT TempCalendar&lt;BR /&gt;ORDER BY TempDate ASC;&lt;/P&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;Have a nice day,&lt;/P&gt;&lt;P&gt;Beata Jablonska&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Feb 2010 12:00:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/YTD-and-MTD-Counts/m-p/215238#M68718</guid>
      <dc:creator />
      <dc:date>2010-02-03T12:00:26Z</dc:date>
    </item>
  </channel>
</rss>

