<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to check specific range of values in Array.</title><link>https://community.appian.com/discussions/f/data/21654/how-to-check-specific-range-of-values-in-array</link><description>The issue that I&amp;#39;m experiencing is that I have an list of dictionary&amp;#39;s. The structure of dictionary&amp;#39;s is like 
 
 { date: 03/05/2021, code: &amp;quot;113&amp;quot;, amount: &amp;quot;0&amp;quot;, id: 4001 }, - END DELAY 
 { date: 01/05/2021, code: &amp;quot;110&amp;quot;, amount: &amp;quot;234&amp;quot;, id: 4002 }, - DELAY</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84792?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 18:31:14 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f5b37d52-a75b-4d3e-aabe-9eb8b8bd41cb</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;Thx.&amp;nbsp;But it&amp;#39;s the same, as the last index of 110 also has the oldest date? I&amp;#39;m not sure how to write this to map the max 110 and 113 so that I can do the calculations properly?.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84789?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 16:37:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5656aaaa-e739-4f59-a8e0-c955b7998ef7</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;In your case max would be based on the date, so max (index (sublist, &amp;quot;Date&amp;quot;))&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84787?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 15:56:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:05bc3b8f-2962-4d16-aa55-1c8f7f946b90</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;No worries, this update pulls only the maximum delay that has &lt;em&gt;ended&lt;/em&gt; within the past year.&amp;nbsp; Change the commenting on the final WHERE clauses to flip to use delays that have &lt;em&gt;started&lt;/em&gt; within the past year.&amp;nbsp; As, a delay could start 14 months ago and end 10 months ago.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="sql"&gt;SELECT
max(daysDelayed) &amp;#39;delayDays&amp;#39;
FROM
(
	SELECT
	[id],
	[date],
	[code],
	[amount],
	[delayEnd],
	DATEDIFF(
		day,
		[date],
		[delayEnd]
	)+15 &amp;#39;daysDelayed&amp;#39;
	FROM
	(
		SELECT
		t.[id],
		t.[date],
		t.[code],
		t.[amount],
		CASE 
			WHEN (t.[code]=110) THEN
				CASE 
					WHEN EXISTS (select * from chris_test_table t2 where t2.[date]&amp;gt;t.[date] and t2.[code]=113) THEN 
						(select min(date) from chris_test_table t3 where t3.[date]&amp;gt;t.[date] and t3.[code]=113)
					ELSE 
						CAST(GETDATE() AS DATE)
				END
			ELSE null
		END as &amp;#39;delayEnd&amp;#39;
		FROM chris_test_table t
	) a
	--WHERE a.[date]&amp;gt;=CAST(DATEADD(year,-1,GETDATE()) as DATE) -- Uses delay START
	WHERE a.[delayEnd]&amp;gt;=CAST(DATEADD(year,-1,GETDATE()) as DATE) -- Uses delay END
) b&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/chris_5F00_21654_5F00_3.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84786?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 15:54:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:eb67891c-d2cd-4ca1-989e-4c2f65914187</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;So What I have done is that based on your suggestion is:&lt;br /&gt;I have created the list of dictionaries as originally described. &lt;br /&gt;For that list, I have extracted the indexes of code 113, &lt;br /&gt;I have used those indexes as indices for the new list of lists, and this part is working fine. &lt;br /&gt;Then I have extracted all 110 of that sublists and also their indexes. I have gotten a Max index of all 110 from all chunks. &lt;br /&gt;What I should do is to map this but I&amp;#39;m missing something. I have tried but no luck still. &lt;br /&gt;Did I go in the wrong direction? Thx.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84785?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 15:43:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:68392292-acf7-45cc-ae7e-32691efe06dc</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;Thx Chris for this. The time range is -1 year from today that is the date interval to be checked. So -365 days from today. I misplaced this info.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84783?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 15:28:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:be1081d3-097f-4c99-bd4c-006702eaa965</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Just to button up the SQL view solution here, you can certainly add 15 days to each delay and calculate a running delay by utilizing the current date (when no 113 present).&lt;/p&gt;
&lt;p&gt;This adjustment assumes you want the longest delay in each calendar year based on the delay start date, which can be adjusted to end date as well.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="sql"&gt;SELECT
DATEPART(year,[date]) &amp;#39;delayYear&amp;#39;,
max(daysDelayed) &amp;#39;delayDays&amp;#39;
FROM
(
	SELECT
	[id],
	[date],
	[code],
	[amount],
	[delayEnd],
	DATEDIFF(
		day,
		[date],
		[delayEnd]
	)+15 &amp;#39;daysDelayed&amp;#39;
	FROM
	(
		SELECT
		t.[id],
		t.[date],
		t.[code],
		t.[amount],
		CASE 
			WHEN (t.[code]=110) THEN
				CASE 
					WHEN EXISTS (select * from chris_test_table t2 where t2.[date]&amp;gt;t.[date] and t2.[code]=113) THEN 
						(select min(date) from chris_test_table t3 where t3.[date]&amp;gt;t.[date] and t3.[code]=113)
					ELSE 
						CAST(GETDATE() AS DATE)
				END
			ELSE null
		END as &amp;#39;delayEnd&amp;#39;
		FROM chris_test_table t
	) a
)b
GROUP BY DATEPART(year,b.[date])&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I added a few rows for 2021 code 110&amp;#39;s with no ending 113, results for year and longest delay:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/chris_5F00_21654_5F00_2.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84772?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 13:03:13 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e785acc9-3b38-4933-a0d4-fcce36b7d02a</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;Try yourself and in a few hours if you haven&amp;#39;t got it I might give it a try.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84771?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 13:00:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9283cac6-de8d-4367-af3c-f0ba0d783e36</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;&amp;nbsp;Could you please provide me with a code example for this? Thx in advance.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84769?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 12:47:13 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:778b1e5b-251a-476c-977a-cbaa574aa1de</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;Yeah, you&amp;#39;ll be getting the positions relative to each individual list.&amp;nbsp; If you grab the ID from that position in each list, and that should map to the right object in the parent, local!list.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84762?ContentTypeID=1</link><pubDate>Thu, 19 Aug 2021 12:25:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3000624f-6adf-4b46-a8b1-15fda972411c</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;This is really helpful as I was able to break up my list to the indexes of code 113. Thx. The part that is not working for me is that I do need to do some calculations with code 113 and last code 110 from the broke up sublists. that I don&amp;#39;t know how to find. Basically, the upper code that you provided is returning ok, and the pseudo &amp;quot;&lt;span&gt;Then forEach sublist, index(max( wherecontains(code 110))) That should get you {3, 7, 13 [if that's the end of the list for that one]} Put THAT in a local variable.&lt;/span&gt;&amp;quot; I&amp;#39;m getting 3,4,6 as the index of the positions of sublists that code 110 contains.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84732?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 22:12:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:3f2ab2db-72f0-4532-84bd-b28f199312e2</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!list: {1001, 1015, 1023, 1025, 1048, 1052, 1067, 1085, 1093, 1099, 1100, 1120, 1130},
  local!indeces: {1, 5, 11},
  a!forEach(
    items:local!indeces,
    expression: if(
      fv!islast,
      index(
        local!list,
        enumerate(length(local!list) - fv!item + 1) + fv!item
      ),
      index(
        local!list,
        enumerate(local!indeces[fv!index + 1] - fv!item) + fv!item
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84731?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 21:38:08 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c9b32f39-2012-4bf9-9c44-0c06e64e080d</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;Do you have an idea how to break up the list that doesn&amp;#39;t have a fixed value for the number of elements into a list of lists (&amp;nbsp;&lt;span&gt;{{1,2,3},{4,5,6,7},{8, 9, 10, 11, 12, 13}}&lt;/span&gt; ) as you suggested? As this was just an example, events 113 and 110 can occur anytime and as many times I wont have same structure everytime so, we again return to the original question how do I know what is the end and star of my list/lists/chunks of data?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84730?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 21:30:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:73ca0541-edf6-4cc2-ab05-0aee646d9892</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;Thx. Chris for this but this is not ideal for me as an additional requirement is needed for my calculation. I can have a case with no 113 events as the client has an active delay with no end.&amp;nbsp; Also, the time range where I need to check this is 1 year and on every chunk of delay data, I need to add + 15 days as this is a requirement, for the calculation as the delay starts 15 days before the first 110 event.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84723?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 19:57:44 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a0ad502f-9bf6-4685-ae77-746133660543</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;If you can calculate this based on your data store, that would be my preference.&amp;nbsp; This could be done in Appian however, with a little additional overhead.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This an example&amp;nbsp;with MSSQL, over table chris_test_table (id,date,code,amount)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;SELECT
[id]
[date],
[code],
[amount],
[delayStart],
DATEDIFF(
	day,
	[delayStart],
	[date]
) &amp;#39;daysDelayed&amp;#39;
FROM
(
	SELECT
	t.[id],
	t.[date],
	t.[code],
	t.[amount],
	CASE -- Return minimum 110 that is after the prior 113
		WHEN (t.[code] = 113) THEN -- End of Delay
			(
				SELECT min(date) from chris_test_table t2 where t2.date&amp;lt;t.date and code=110 and t2.date &amp;gt;= 
				CASE -- If no prior 113s, return first 110
					WHEN EXISTS (select * from chris_test_table t3 where t3.date&amp;lt;t.date and t3.code=113) THEN
						(select max(date) from chris_test_table t4 where t4.date&amp;lt;t.date and t4.code=113)
					ELSE 
						(select min(date) from chris_test_table t5 where code=110)
				END
			)
		ELSE null
	END as &amp;#39;delayStart&amp;#39;
	FROM chris_test_table t
) a
ORDER BY [date] asc&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This could be expanded as necessary and tied to a CDT in your application for easy access.&lt;/p&gt;
&lt;p&gt;The output puts the final delay details on the lines with the 113 / closing event as:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/chris_5F00_21654.JPG" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84721?ContentTypeID=1</link><pubDate>Wed, 18 Aug 2021 18:15:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:882a51e9-a62d-4355-81f1-706f862d522f</guid><dc:creator>davel001150</dc:creator><description>&lt;p&gt;Let&amp;#39;s see.&lt;/p&gt;
&lt;p&gt;Perhaps use wherecontains to get the index of every 113.&amp;nbsp; In example above you would have {1, 4, 8}.&amp;nbsp; Put that in a local variable.&lt;/p&gt;
&lt;p&gt;Now, break up the list into a list of lists, {{1,2,3},{4,5,6,7},{8, 9, 10, 11, 12, 13}}.&amp;nbsp; Put that in a local variable.&lt;/p&gt;
&lt;p&gt;Then forEach sublist, index(max( wherecontains(code 110))) That should get you {3, 7, 13 [if that's the end of the list for that one]} Put THAT in a local variable.&lt;/p&gt;
&lt;p&gt;Now, for each in {1, 4, 8},&amp;nbsp;subtract date at that index from date at {3, 7, and 13}&amp;nbsp; Now, you&amp;#39;ll have a list of time intervals.&amp;nbsp; Wrap this last forEach in a max() function, should have it.&amp;nbsp; May be ways of tweaking this to work more efficient, but it&amp;#39;s how I would start.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84692?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 19:22:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:77dc71c4-fba7-469f-a3d0-f51aa44b037a</guid><dc:creator>Darko</dc:creator><description>&lt;p&gt;Basically this data is returned from integration call with complex structure and stored in DB later on so just to answer your question, Yes it is stored. Any idea about this logic?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check specific range of values in Array.</title><link>https://community.appian.com/thread/84688?ContentTypeID=1</link><pubDate>Tue, 17 Aug 2021 17:42:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:30bf6bde-8350-4ec0-948b-da37e1355680</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;This is interesting logic to create rules for.. Just to confirm, this data is &lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;not&lt;/span&gt; &lt;/strong&gt;stored in a database?&amp;nbsp; Typically I would do this type of calculation within a view on the DB side.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>