<?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: Setting a Flag in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979800#M80866</link>
    <description>&lt;P&gt;Hi, you can do a sorte load using Peek() to check the last row values. Maybe you also need a field that uses date and time to chek the 2 hours difference between days, it would be something like:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;OriginalData:
LOAD Date, ID, Time, Date+Time as DateTime
Resident/from...

PrecessedData:
LOAD ID, Date, Time,
  If(Peek(ID)&amp;lt;&amp;gt;ID
    ,DateTime // Is the first row of the ID, this datetime is flagged
    ,If(Peek(LastFlag)+(2/24)&amp;gt;DateTime // If there are less than 2 hours from the last flag...
      ,Peek(LastFlag) // .. The last time flagged is copied..
      ,DateTime)) as LastFlag, // .. else this is the new date
  If(Peek(ID)&amp;lt;&amp;gt;ID
    ,1 // Is the first row of the ID, this is flagged
    ,If(Peek(LastFlag)+(2/24)&amp;gt;DateTime
      ,0 // Last time plus 2 hours is lower that this datetime
      ,1)) as Flag, // More than 2 hours since the last flag
Resident OriginalData
ORder By ID, Datetime;

DROP Table OriginalData;

      &lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 12 Sep 2022 11:44:04 GMT</pubDate>
    <dc:creator>rubenmarin</dc:creator>
    <dc:date>2022-09-12T11:44:04Z</dc:date>
    <item>
      <title>Setting a Flag</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979730#M80863</link>
      <description>&lt;P&gt;Hi , I trying to set a flag for every "ID"&amp;nbsp; where first entry&amp;nbsp; is flagged 1 and there after flag next entry as 1 only if it is greater than 2hours from first flag . Sample data&lt;/P&gt;
&lt;TABLE width="410"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="46px"&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="161.85px" height="46px"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="46.5833px" height="46px"&gt;&lt;STRONG&gt;Time&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="116.433px" height="46px"&gt;&lt;EM&gt;&lt;STRONG&gt;Desired Flag Output&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;04:36&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:07&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:10&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:21&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:29&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:37&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:58&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;08:29&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;18:00&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-01&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;18:32&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;04:35&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:06&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:12&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;05:23&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:24&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:28&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;07:58&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;08:29&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;17:59&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;1867175215046269447&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;18:28&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;18:36&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84.3333px" height="24px"&gt;2022-03-02&lt;/TD&gt;
&lt;TD width="161.85px" height="24px"&gt;6279882763709393&lt;/TD&gt;
&lt;TD width="46.5833px" height="24px"&gt;19:02&lt;/TD&gt;
&lt;TD width="116.433px" height="24px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 12 Sep 2022 09:44:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979730#M80863</guid>
      <dc:creator>Ironzem</dc:creator>
      <dc:date>2022-09-12T09:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Flag</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979800#M80866</link>
      <description>&lt;P&gt;Hi, you can do a sorte load using Peek() to check the last row values. Maybe you also need a field that uses date and time to chek the 2 hours difference between days, it would be something like:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;OriginalData:
LOAD Date, ID, Time, Date+Time as DateTime
Resident/from...

PrecessedData:
LOAD ID, Date, Time,
  If(Peek(ID)&amp;lt;&amp;gt;ID
    ,DateTime // Is the first row of the ID, this datetime is flagged
    ,If(Peek(LastFlag)+(2/24)&amp;gt;DateTime // If there are less than 2 hours from the last flag...
      ,Peek(LastFlag) // .. The last time flagged is copied..
      ,DateTime)) as LastFlag, // .. else this is the new date
  If(Peek(ID)&amp;lt;&amp;gt;ID
    ,1 // Is the first row of the ID, this is flagged
    ,If(Peek(LastFlag)+(2/24)&amp;gt;DateTime
      ,0 // Last time plus 2 hours is lower that this datetime
      ,1)) as Flag, // More than 2 hours since the last flag
Resident OriginalData
ORder By ID, Datetime;

DROP Table OriginalData;

      &lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 12 Sep 2022 11:44:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979800#M80866</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2022-09-12T11:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Flag</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979975#M80882</link>
      <description>&lt;P&gt;Hi Rubenmarin&lt;/P&gt;
&lt;P&gt;Thank you for your time , I tried your script but I get all the rows flagged as 1 . I thought it might be the DateTime combination , so I used a Timestamp function to join with format(YY..) , but I got same results. Please see attached my script, the field names are bit different because my earlier data was shown with labels. the flag calculation is identical as you supplied. Attached also the CSV of sample data if required. Please check my script if I have done it correctly. Thank You&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ironzem_0-1663001672271.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/88925iB9A5BF466D37F0B1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ironzem_0-1663001672271.png" alt="Ironzem_0-1663001672271.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 16:57:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1979975#M80882</guid>
      <dc:creator>Ironzem</dc:creator>
      <dc:date>2022-09-12T16:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Flag</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1980726#M80934</link>
      <description>&lt;P&gt;Hi, I see my answer marked as correct, that means that you already solved the issue? or still all rows are flagged as 1?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 06:39:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1980726#M80934</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2022-09-14T06:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a Flag</title>
      <link>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1982846#M81110</link>
      <description>&lt;P&gt;Thanks Rubenmarin&lt;/P&gt;
&lt;P&gt;Your initial answer was perfect , error on my side when implementing .&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 04:10:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Setting-a-Flag/m-p/1982846#M81110</guid>
      <dc:creator>Ironzem</dc:creator>
      <dc:date>2022-09-20T04:10:44Z</dc:date>
    </item>
  </channel>
</rss>

