<?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: countif on historic data with a stop condition in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/countif-on-historic-data-with-a-stop-condition/m-p/1590630#M443541</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If scripting is an option you can use Peek to set a counter that resets on new project/non red/amber status. Not sure I follow your thing on the dates, but think you would do similar (but need to incorporate the date). I've pasted script below as I have personal edition, here is the result (I've added a flag to show last date by project;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20190611_1.png" style="width: 594px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13571iF83D24FBD9531DB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="20190611_1.png" alt="20190611_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Let me know if this helps (and is right/wrong) and I can have a think about the date change.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Chris.&lt;/P&gt;&lt;P&gt;Script&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;data:
LOAD * INLINE [
Data_Captured_Date, Project_Name, RAG_Status, Return_To_Green_Date
06/05/2019, Project A, RED, 15/05/2019
13/05/2019, Project A, RED, 15/05/2019
20/05/2019, Project A, GREEN, 
27/05/2019, Project A, AMBER, 05/06/2019
03/06/2019, Project A, RED, 05/06/2019
10/06/2019, Project A, RED, 20/06/2019
03/06/2019, Project B, AMBER, 25/06/2019
10/06/2019, Project B, AMBER, 25/06/2019
03/06/2019, Project C, AMBER, 25/06/2019
10/06/2019, Project C, GREEN, 
];

data_final:
NoConcatenate
Load
	If(RowNo()=1,
		If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,1,0),
		If(Peek(Project_Name)&amp;lt;&amp;gt;Project_Name,
			If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,1,0),
			If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,Peek([Adverse Period])+1,0)
			)
		) AS [Adverse Period],
	*
Resident data
Order by Project_Name, Data_Captured_Date;

Left Join (data_final)
Load
	Max(Data_Captured_Date) AS Data_Captured_Date,
	Project_Name,
	1 AS Max_Date
Resident data_final
Group by Project_Name;

DROP TABLE data;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2019 19:18:55 GMT</pubDate>
    <dc:creator>chrismarlow</dc:creator>
    <dc:date>2019-06-11T19:18:55Z</dc:date>
    <item>
      <title>countif on historic data with a stop condition</title>
      <link>https://community.qlik.com/t5/QlikView/countif-on-historic-data-with-a-stop-condition/m-p/1590434#M443528</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This question may have been covered off elsewhere in the forums before however i wasn't sure where to even start searching.&lt;/P&gt;&lt;P&gt;I have a history data set with the following columns:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Data_Captured_Date&lt;/LI&gt;&lt;LI&gt;Project_Name&lt;/LI&gt;&lt;LI&gt;RAG_Status&lt;/LI&gt;&lt;LI&gt;Return_To_Green_Date&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The RAG_Status column can have a value of Red, Amber, Green or Gray.&lt;/P&gt;&lt;P&gt;The Return_To_Green_Date will only be populated if the RAG status is adverse (i.e. Red or Amber).&lt;/P&gt;&lt;P&gt;The history file is appended on a weekly basis to add new data - in this way a project will build up a history of its movements between RAG status'.&lt;/P&gt;&lt;P&gt;i need to perform the following calculations:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Number of previous weeks that the project has been adverse (Red or Amber). However if at any point the RAG status moves to Green then the counter resets to 0.&lt;/LI&gt;&lt;LI&gt;Number of times that the Return_To_Green_Date changes within an adverse period&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;data set example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;Data_Captured_Date&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;Project_Name&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;RAG_Status&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;Return_To_Green_Date&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;06/05/19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Project A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;RED&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;15/05/19&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;13/05/19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Project A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;RED&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;15/05/19&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;20/05/19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Project A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt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t;&lt;P&gt;25/06/19&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;03/06/19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Project C&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;AMBER&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;25/06/19&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;10/06/19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Project C&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;GREEN&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the logic works correctly the following should be true:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Project &lt;STRONG&gt;A&lt;/STRONG&gt; has been adverse (Red Or Amber RAG_Status) for the last 3 weeks&lt;/LI&gt;&lt;LI&gt;Project &lt;STRONG&gt;A&lt;/STRONG&gt;'s Return_To_Green_Date has changed 1 time within that 3 week period&lt;/LI&gt;&lt;LI&gt;Project &lt;STRONG&gt;B&lt;/STRONG&gt; has been adverse for&amp;nbsp;(Red Or Amber RAG_Status) for the last 2 weeks&lt;/LI&gt;&lt;LI&gt;Project &lt;STRONG&gt;B&lt;/STRONG&gt;'s Return_To_Green_Date has changed 0 times within that 2 week period&lt;/LI&gt;&lt;LI&gt;Project &lt;STRONG&gt;C&lt;/STRONG&gt;&amp;nbsp;has been adverse (Red Or Amber RAG_Status) for 0 weeks&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If anybody has any ideas how I should go about formulating these calculations i would really appreciate it!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 11:45:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/countif-on-historic-data-with-a-stop-condition/m-p/1590434#M443528</guid>
      <dc:creator>chrismtb</dc:creator>
      <dc:date>2019-06-11T11:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: countif on historic data with a stop condition</title>
      <link>https://community.qlik.com/t5/QlikView/countif-on-historic-data-with-a-stop-condition/m-p/1590630#M443541</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;If scripting is an option you can use Peek to set a counter that resets on new project/non red/amber status. Not sure I follow your thing on the dates, but think you would do similar (but need to incorporate the date). I've pasted script below as I have personal edition, here is the result (I've added a flag to show last date by project;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20190611_1.png" style="width: 594px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13571iF83D24FBD9531DB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="20190611_1.png" alt="20190611_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Let me know if this helps (and is right/wrong) and I can have a think about the date change.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Chris.&lt;/P&gt;&lt;P&gt;Script&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;data:
LOAD * INLINE [
Data_Captured_Date, Project_Name, RAG_Status, Return_To_Green_Date
06/05/2019, Project A, RED, 15/05/2019
13/05/2019, Project A, RED, 15/05/2019
20/05/2019, Project A, GREEN, 
27/05/2019, Project A, AMBER, 05/06/2019
03/06/2019, Project A, RED, 05/06/2019
10/06/2019, Project A, RED, 20/06/2019
03/06/2019, Project B, AMBER, 25/06/2019
10/06/2019, Project B, AMBER, 25/06/2019
03/06/2019, Project C, AMBER, 25/06/2019
10/06/2019, Project C, GREEN, 
];

data_final:
NoConcatenate
Load
	If(RowNo()=1,
		If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,1,0),
		If(Peek(Project_Name)&amp;lt;&amp;gt;Project_Name,
			If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,1,0),
			If(Match(RAG_Status,'RED','AMBER')&amp;gt;0,Peek([Adverse Period])+1,0)
			)
		) AS [Adverse Period],
	*
Resident data
Order by Project_Name, Data_Captured_Date;

Left Join (data_final)
Load
	Max(Data_Captured_Date) AS Data_Captured_Date,
	Project_Name,
	1 AS Max_Date
Resident data_final
Group by Project_Name;

DROP TABLE data;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 19:18:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/countif-on-historic-data-with-a-stop-condition/m-p/1590630#M443541</guid>
      <dc:creator>chrismarlow</dc:creator>
      <dc:date>2019-06-11T19:18:55Z</dc:date>
    </item>
  </channel>
</rss>

