<?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>article Creating Rolling N Month Flag in the script in Member Articles</title>
    <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/ta-p/1484325</link>
    <description>&lt;P&gt;The rolling months method is frequently utilized in business analytics and financial reporting to provide a more accurate representation of performance over time. This document demonstrates how to create a flag in the script to perform rolling N months analysis.&lt;/P&gt;
&lt;P&gt;There are various ways to achieve rolling month analysis in graphs using the rangesum() function in conjunction with the above() function on the front end, along with set analysis. While front-end solutions work well for simpler measures and smaller datasets, they can lead to performance issues or increased complexity in cases of more intricate requirements.&lt;/P&gt;
&lt;P&gt;Therefore, it is advisable to create a flag in the script using a master calendar.&lt;/P&gt;
&lt;P&gt;This approach will establish a flag in the script for rolling months, which can then be used as a filter or in set analysis measures on the front end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// Load min and max Date from Fact

MaxDate:
LOAD num(max(FieldValue('Date', recno()))) as MaxDate,
     num(min(FieldValue('Date', recno()))) as MinDate
AUTOGENERATE FieldValueCount('Date');

let vMaxDate= Peek('MaxDate',0,'MaxDate');
let vMinDate= Peek('MinDate',0,'MaxDate');

drop table MaxDate;

// Generate Dates using min and max date
Cal:
LOAD *,
     MonthName(Date) as MonthYear;
LOAD date($(vMinDate)+IterNo()-1) as Date
AutoGenerate(1)
While $(vMinDate)+IterNo()-1&amp;lt;=$(vMaxDate);

MaxMonthYear:
LOAD num(max(FieldValue('MonthYear', recno()))) as MaxMonthYear
AUTOGENERATE FieldValueCount('MonthYear');

//  Variable used to restrict MonthYear to &amp;lt;=current month while looping

LET vMaxMonthYear = monthname(Peek('MaxMonthYear',0,'MaxMonthYear'));

// Define Rolling N in Inline table. 1 is the default value for current month

RollMonth:
LOAD * Inline [
RollMonth
1
2
3
6
12 ];

Calender:
LOAD * Inline [
junk ];

for i=1 to FieldValueCount('RollMonth')

LET vRollMonth= FieldValue('RollMonth',$(i));

Concatenate(Calender)
LOAD Date,
     MonthYear,
     Rolling_Months,
     month(Rolling_Months) as Month,
     Year(Rolling_Months) as Year,
     if(Flag='Rolling1','CurrentMonth',Flag) as Rolling_Flag
where Rolling_Months&amp;lt;=Date#('$(vMaxMonthYear)','MMM YYYY');

LOAD Date,
     MonthYear,
     monthname(MonthYear,IterNo()-1) as Rolling_Months,
     'Rolling'&amp;amp;$(vRollMonth) as Flag
Resident Cal
While IterNo()-1&amp;lt;=$(vRollMonth)-1 ;

NEXT

DROP Tables Cal,MaxMonthYear,RollMonth;
DROP Field junk;

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 134307.png" style="width: 907px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171698iC8D0A0E50096B518/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 134307.png" alt="Screenshot 2024-09-16 134307.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Use &lt;STRONG&gt;Rolling_Months&lt;/STRONG&gt; as your month selection or dimension in your report when performing month-based analysis. You can also utilize &lt;STRONG&gt;Rolling_Flag&lt;/STRONG&gt; either as a filter or as a condition in set analysis to construct the required measure.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 133303.png" style="width: 835px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171697i317A8DF37C40EE19/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 133303.png" alt="Screenshot 2024-09-16 133303.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 133402.png" style="width: 898px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171696i99F41710E2F0BB84/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 133402.png" alt="Screenshot 2024-09-16 133402.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Please refer to the attached applications.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2024 18:45:35 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2024-09-25T18:45:35Z</dc:date>
    <item>
      <title>Creating Rolling N Month Flag in the script</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/ta-p/1484325</link>
      <description>&lt;P&gt;The rolling months method is frequently utilized in business analytics and financial reporting to provide a more accurate representation of performance over time. This document demonstrates how to create a flag in the script to perform rolling N months analysis.&lt;/P&gt;
&lt;P&gt;There are various ways to achieve rolling month analysis in graphs using the rangesum() function in conjunction with the above() function on the front end, along with set analysis. While front-end solutions work well for simpler measures and smaller datasets, they can lead to performance issues or increased complexity in cases of more intricate requirements.&lt;/P&gt;
&lt;P&gt;Therefore, it is advisable to create a flag in the script using a master calendar.&lt;/P&gt;
&lt;P&gt;This approach will establish a flag in the script for rolling months, which can then be used as a filter or in set analysis measures on the front end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// Load min and max Date from Fact

MaxDate:
LOAD num(max(FieldValue('Date', recno()))) as MaxDate,
     num(min(FieldValue('Date', recno()))) as MinDate
AUTOGENERATE FieldValueCount('Date');

let vMaxDate= Peek('MaxDate',0,'MaxDate');
let vMinDate= Peek('MinDate',0,'MaxDate');

drop table MaxDate;

// Generate Dates using min and max date
Cal:
LOAD *,
     MonthName(Date) as MonthYear;
LOAD date($(vMinDate)+IterNo()-1) as Date
AutoGenerate(1)
While $(vMinDate)+IterNo()-1&amp;lt;=$(vMaxDate);

MaxMonthYear:
LOAD num(max(FieldValue('MonthYear', recno()))) as MaxMonthYear
AUTOGENERATE FieldValueCount('MonthYear');

//  Variable used to restrict MonthYear to &amp;lt;=current month while looping

LET vMaxMonthYear = monthname(Peek('MaxMonthYear',0,'MaxMonthYear'));

// Define Rolling N in Inline table. 1 is the default value for current month

RollMonth:
LOAD * Inline [
RollMonth
1
2
3
6
12 ];

Calender:
LOAD * Inline [
junk ];

for i=1 to FieldValueCount('RollMonth')

LET vRollMonth= FieldValue('RollMonth',$(i));

Concatenate(Calender)
LOAD Date,
     MonthYear,
     Rolling_Months,
     month(Rolling_Months) as Month,
     Year(Rolling_Months) as Year,
     if(Flag='Rolling1','CurrentMonth',Flag) as Rolling_Flag
where Rolling_Months&amp;lt;=Date#('$(vMaxMonthYear)','MMM YYYY');

LOAD Date,
     MonthYear,
     monthname(MonthYear,IterNo()-1) as Rolling_Months,
     'Rolling'&amp;amp;$(vRollMonth) as Flag
Resident Cal
While IterNo()-1&amp;lt;=$(vRollMonth)-1 ;

NEXT

DROP Tables Cal,MaxMonthYear,RollMonth;
DROP Field junk;

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 134307.png" style="width: 907px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171698iC8D0A0E50096B518/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 134307.png" alt="Screenshot 2024-09-16 134307.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Use &lt;STRONG&gt;Rolling_Months&lt;/STRONG&gt; as your month selection or dimension in your report when performing month-based analysis. You can also utilize &lt;STRONG&gt;Rolling_Flag&lt;/STRONG&gt; either as a filter or as a condition in set analysis to construct the required measure.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 133303.png" style="width: 835px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171697i317A8DF37C40EE19/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 133303.png" alt="Screenshot 2024-09-16 133303.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-16 133402.png" style="width: 898px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/171696i99F41710E2F0BB84/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-16 133402.png" alt="Screenshot 2024-09-16 133402.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Please refer to the attached applications.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 18:45:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/ta-p/1484325</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-09-25T18:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling N months</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484326#M1447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;very useful application. Rolling Months charts required in most of applications&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 05:30:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484326#M1447</guid>
      <dc:creator>manojkulkarni</dc:creator>
      <dc:date>2015-09-14T05:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling N months</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484327#M1448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for sharing this. Pl help me to understand calculation of min and max date from fact table. So far I came across and it works fine by simply using min and max function on the date field to get min and max date from fact. Didn't understand the use of Fieldvalue and FieldValueCount here. Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 07:39:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484327#M1448</guid>
      <dc:creator>Digvijay_Singh</dc:creator>
      <dc:date>2015-09-14T07:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling N months</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484328#M1449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Digvijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This method is the fastest method to calculate Min and Max. You can find the details on below link&lt;/P&gt;&lt;P&gt;&lt;A href="http://qlikviewcookbook.com/2013/09/fastest-method-to-read-maxfield-from-a-qvd/"&gt;http://qlikviewcookbook.com/2013/09/fastest-method-to-read-maxfield-from-a-qvd/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 07:44:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484328#M1449</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2015-09-14T07:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling N months</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484329#M1450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice Explanation!! Thank you for sharing&lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 13:55:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/1484329#M1450</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-14T13:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling N months</title>
      <link>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/2153523#M2123</link>
      <description>&lt;P&gt;How do you use the Flag in the measure? The measure I have created in your app isn't working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/M&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 10:53:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Creating-Rolling-N-Month-Flag-in-the-script/tac-p/2153523#M2123</guid>
      <dc:creator>Mazarinen</dc:creator>
      <dc:date>2023-12-15T10:53:30Z</dc:date>
    </item>
  </channel>
</rss>

