<?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>Get values from nested loop</title><link>https://community.appian.com/discussions/f/data/17448/get-values-from-nested-loop</link><description>Hi, 
 I have 2 arrays: 
 local!years: {&amp;quot;2019&amp;quot;, &amp;quot;2019&amp;quot;, &amp;quot;2018&amp;quot;, &amp;quot;2017&amp;quot;} 
 local!income: {1,2,3,4} 
 So the value in &amp;quot;income&amp;quot; is corresponding to its year in the &amp;quot;years&amp;quot;. 
 and I want to get this data like : &amp;quot;year&amp;quot; - sum(&amp;quot;income&amp;quot;) 
 2019 - 3 
 2018 - 3</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Get values from nested loop</title><link>https://community.appian.com/thread/68779?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 13:43:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:11af1315-6e94-41fa-a14d-db301a0a8718</guid><dc:creator>ramanh</dc:creator><description>&lt;p&gt;Thanks now it works&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get values from nested loop</title><link>https://community.appian.com/thread/68775?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 13:28:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f76e8689-944b-4b17-bc04-2e2895009199</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;The issue here is that you can&amp;#39;t push any new values into a local variable from subsequent code like this (like in your a!forEach loop here).&amp;nbsp; And&amp;nbsp;for total clarification, the &amp;quot;=&amp;quot; operator always compares values, it doesn&amp;#39;t change anything, and the &amp;quot;==&amp;quot; operator doesn&amp;#39;t exist in Appian (I know you may have just written it that way as an example though, but I don&amp;#39;t want others seeing this to potentially get confused).&lt;/p&gt;
&lt;p&gt;The solution already posted by &lt;a href="/members/arunc"&gt;arunkumarc&lt;/a&gt; should work - basically what&amp;#39;s happening there is, you create a new list of just the unique years, then iterate over each one of those, and for any given (unique) year, you check the original Years and Income arrays, and sum any members of the Income array at positions matching the current year in the Years array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get values from nested loop</title><link>https://community.appian.com/thread/68773?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2019 10:16:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1d273d6e-ee14-4f64-b837-9c20ab4ce8c5</guid><dc:creator>arunkumarc</dc:creator><description>&lt;p&gt;Please have a look on below code :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;load(&lt;br /&gt; local!years: {&lt;br /&gt; &amp;quot;2019&amp;quot;,&lt;br /&gt; &amp;quot;2019&amp;quot;,&lt;br /&gt; &amp;quot;2018&amp;quot;,&lt;br /&gt; &amp;quot;2017&amp;quot;&lt;br /&gt; },&lt;br /&gt; local!income: {&lt;br /&gt; 10,&lt;br /&gt; 20,&lt;br /&gt; 30,&lt;br /&gt; 40&lt;br /&gt; },&lt;br /&gt; local!uniquerYears: union(&lt;br /&gt; local!years,&lt;br /&gt; local!years&lt;br /&gt; ),&lt;br /&gt; local!result: a!forEach(&lt;br /&gt; items: local!uniquerYears,&lt;br /&gt; expression: {&lt;br /&gt; year: fv!item,&lt;br /&gt; Totalsum: sum(&lt;br /&gt; index(&lt;br /&gt; local!income,&lt;br /&gt; wherecontains(&lt;br /&gt; fv!item,&lt;br /&gt; local!years&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; ),&lt;br /&gt; local!result&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>