<?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>help to create rule to calculate data based on the previous iteration</title><link>https://community.appian.com/discussions/f/rules/35567/help-to-create-rule-to-calculate-data-based-on-the-previous-iteration</link><description>I have this array {100, 50, 20,50,10} and a variable x = 600, I need help to create a rule that creates an array with the results that must be calculated in this way:

The first value of the array must be subtracted with the variable x, the result must</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: help to create rule to calculate data based on the previous iteration</title><link>https://community.appian.com/thread/138803?ContentTypeID=1</link><pubDate>Tue, 30 Jul 2024 05:20:20 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bd2579c8-f281-4cc0-91a2-07d69eaa6f73</guid><dc:creator>gayathris876948</dc:creator><description>&lt;p&gt;a!localVariables(&lt;br /&gt; local!regularizaciones: { 100, 50, 20, 50, 10 },&lt;br /&gt; local!initialValue: 600,&lt;br /&gt; /* Define the reduce function */&lt;br /&gt; local!resultArray: reduce(&lt;br /&gt; rule!subtractionAccumulator,&lt;br /&gt; { local!initialValue },&lt;br /&gt; local!regularizaciones,&lt;br /&gt; &lt;br /&gt; ),&lt;br /&gt; local!resultArray&lt;br /&gt;)&lt;/p&gt;
&lt;p&gt;/* Helper function to accumulate subtraction results */&lt;br /&gt;rule!subtractionAccumulator&lt;/p&gt;
&lt;p&gt;ri!lastResult - ri!currentValue&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help to create rule to calculate data based on the previous iteration</title><link>https://community.appian.com/thread/138684?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 05:21:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1a657b41-e1ed-4bd6-9e5e-aa44de8dcfb7</guid><dc:creator>venkatrea696188</dc:creator><description>&lt;p&gt;Hello, You should mention sample output (It would help us a lot) .have a look into the code the output of this code looks like {500,450,430,380,370}&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!regularizaciones: {100, 50, 20,50,10},
  local!initialValue: 600,
a!forEach(
  items: local!regularizaciones,
  expression: a!localVariables(
    local!subtractedarray:if(
      fv!index=1,
      local!initialValue-fv!item,
      local!initialValue-sum(index(local!regularizaciones,(enumerate(fv!index)+1),null))
    ),
    {local!subtractedarray}
  )
)

)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: help to create rule to calculate data based on the previous iteration</title><link>https://community.appian.com/thread/138683?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2024 04:45:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4a12332c-bb52-4954-a58a-1ce7858cfe2b</guid><dc:creator>Yogi Patel</dc:creator><description>&lt;p&gt;You can use the reduce function. See the following sample code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!regularizaciones: { 100, 50, 20, 50, 10 },
  local!initialValue: 600,
  reduce(
    fn!sum,
    local!regularizaciones[1] - local!initialValue,
    ldrop(local!regularizaciones, 1) * ( - 1)
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>