<?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: Create Current Week/Next Week Flag based on Given Date in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743766#M720753</link>
    <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/94877"&gt;@AleRods88&lt;/a&gt;&amp;nbsp; try below conditions. assuming you have correct date format to the date field&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;LOAD *,
  if(OP_DATE &amp;lt;= WeekStart(Today(),0,4),'Previous Week',
  if(OP_DATE&amp;gt;=WeekStart(Today(),0,4) and OP_DATE&amp;lt;=WeekEnd(Today(),0,4)+1,'Current Week',
  if(OP_DATE&amp;gt;=WeekStart(Today(),1,4) and OP_DATE&amp;lt;=WeekEnd(Today(),1,4)+1,'Next Week','Rest'))) as Week_Status&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Sep 2020 22:27:18 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2020-09-14T22:27:18Z</dc:date>
    <item>
      <title>Create Current Week/Next Week Flag based on Given Date</title>
      <link>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743739#M720749</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a field named OP_DATE (MM/DD/YYYY) with all Friday dates like this:&lt;/P&gt;&lt;TABLE border="0" width="80" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;OP_DATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;09/04/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;09/11/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;09/18/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;09/25/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;10/02/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="79px" height="15px"&gt;10/09/2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is to create a new field, named WEEK_STATUS, with values: "Current Week", "Next Week", "Previous" and "Rest".&lt;/P&gt;&lt;P&gt;So with this, I would have flagged each OP_DATE, depending if I am standing in the current week (with Today()) or not:&lt;/P&gt;&lt;TABLE border="0" width="160" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;OP_DATE&lt;/TD&gt;&lt;TD width="80"&gt;WEEK_STATUS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;9/4/2020&lt;/TD&gt;&lt;TD&gt;Previous&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;9/11/2020&lt;/TD&gt;&lt;TD&gt;Previous&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;09/18/2020&lt;/TD&gt;&lt;TD&gt;Current Week&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;09/25/2020&lt;/TD&gt;&lt;TD&gt;Next Week&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;10/2/2020&lt;/TD&gt;&lt;TD&gt;Rest&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80" height="20"&gt;10/9/2020&lt;/TD&gt;&lt;TD&gt;Rest&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Note&lt;/U&gt;: The "Current Week" status should stay until this Friday inclusive, so the week goes from Monday to Friday.&lt;/P&gt;&lt;P&gt;I'd need to do this by Script and I'll reload the application each day, so the field WEEK_STATUS should change from week to week.&lt;/P&gt;&lt;P&gt;Is there any what to do this?&lt;/P&gt;&lt;P&gt;Thank you!!!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743739#M720749</guid>
      <dc:creator>AleRods88</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create Current Week/Next Week Flag based on Given Date</title>
      <link>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743761#M720751</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Certainly, this is a common logic that we apply in any Master Calendar load. You build your flags based on the relation between today's date and the date field value. You can use some of the available Date and Time functions, or you can use simple numeric conditions for these flags. For example:&lt;/P&gt;&lt;P&gt;LET vToday = num(Today());&lt;/P&gt;&lt;P&gt;Calendar:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; OP_DATE,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; IF($(vToday) - OP_DATE&amp;gt;=0 and&amp;nbsp;$(vToday) - OP_DATE &amp;lt;=5, 'Current Week',&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; IF($(vToday) - OP_DATE&amp;gt;=8 and&amp;nbsp;$(vToday) - OP_DATE &amp;lt;=12, 'Previous Week', 'Rest')) as WEEK_STATUS,&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;I'd only make one comment... In my practice, I found it more convenient to work with numeric flags that hold values 0 and 1 - for example, _This_Week_Flag, _Last_Week_Flag, etc... This way, the fields are easy to use in Set Analysis, or they can be used as simple multipliers for your metrics. For example:&lt;/P&gt;&lt;P&gt;This Week Sales = sum(Sales * _This_Week_Flag)&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 22:11:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743761#M720751</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2020-09-14T22:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create Current Week/Next Week Flag based on Given Date</title>
      <link>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743766#M720753</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/94877"&gt;@AleRods88&lt;/a&gt;&amp;nbsp; try below conditions. assuming you have correct date format to the date field&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;LOAD *,
  if(OP_DATE &amp;lt;= WeekStart(Today(),0,4),'Previous Week',
  if(OP_DATE&amp;gt;=WeekStart(Today(),0,4) and OP_DATE&amp;lt;=WeekEnd(Today(),0,4)+1,'Current Week',
  if(OP_DATE&amp;gt;=WeekStart(Today(),1,4) and OP_DATE&amp;lt;=WeekEnd(Today(),1,4)+1,'Next Week','Rest'))) as Week_Status&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 22:27:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Create-Current-Week-Next-Week-Flag-based-on-Given-Date/m-p/1743766#M720753</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-09-14T22:27:18Z</dc:date>
    </item>
  </channel>
</rss>

