<?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: How to use Foreach for multiple columns and multiple rows? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525855#M148412</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/136781"&gt;@renjith_nair&lt;/a&gt;&amp;nbsp;thanks for the answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Oct 2020 16:16:27 GMT</pubDate>
    <dc:creator>ChioNeng</dc:creator>
    <dc:date>2020-10-21T16:16:27Z</dc:date>
    <item>
      <title>How to use Foreach for multiple columns and multiple rows?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525043#M148125</link>
      <description>&lt;P&gt;Hello, I'm having trouble figuring out how to use foreach + eval getting the difference of the fields.&lt;/P&gt;&lt;P&gt;I have something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="have.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/11331i62E7D87B2FD30385/image-size/large?v=v2&amp;amp;px=999" role="button" title="have.PNG" alt="have.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;You can use this search to obtained the above result:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;| makeresults&lt;BR /&gt;| eval Country="PH"&lt;BR /&gt;| eval "2020-01 Actual"=1&lt;BR /&gt;| eval "2020-01 Forecast"=2&lt;BR /&gt;| eval "2020-02 Actual"=5&lt;BR /&gt;| eval "2020-02 Forecast"=4&lt;BR /&gt;| eval "2020-03 Actual"=50&lt;BR /&gt;| eval "2020-03 Forecast"=20&lt;BR /&gt;| append&lt;BR /&gt;[| makeresults&lt;BR /&gt;| eval Country="IND"&lt;BR /&gt;| eval "2020-01 Actual"=3&lt;BR /&gt;| eval "2020-01 Forecast"=3&lt;BR /&gt;| eval "2020-02 Actual"=2&lt;BR /&gt;| eval "2020-02 Forecast"=2&lt;BR /&gt;| eval "2020-03 Actual"=40&lt;BR /&gt;| eval "2020-03 Forecast"=23&lt;BR /&gt;]&lt;BR /&gt;| append&lt;BR /&gt;[| makeresults&lt;BR /&gt;| eval Country="SG"&lt;BR /&gt;| eval "2020-01 Actual"=2&lt;BR /&gt;| eval "2020-01 Forecast"=4&lt;BR /&gt;| eval "2020-02 Actual"=1&lt;BR /&gt;| eval "2020-02 Forecast"=9&lt;BR /&gt;| eval "2020-03 Actual"=30&lt;BR /&gt;| eval "2020-03 Forecast"=53 ]&lt;BR /&gt;| fields - _time&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And I'm trying to use foreach/eval to get this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="want.PNG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/11332i4BC23C1C3D2715CD/image-size/large?v=v2&amp;amp;px=999" role="button" title="want.PNG" alt="want.PNG" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 11:51:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525043#M148125</guid>
      <dc:creator>ChioNeng</dc:creator>
      <dc:date>2020-10-16T11:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Foreach for multiple columns and multiple rows?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525054#M148128</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval Country="PH"
| eval "2020-01 Actual"=1
| eval "2020-01 Forecast"=2
| eval "2020-02 Actual"=5
| eval "2020-02 Forecast"=4
| eval "2020-03 Actual"=50
| eval "2020-03 Forecast"=20
| append
[| makeresults
| eval Country="IND"
| eval "2020-01 Actual"=3
| eval "2020-01 Forecast"=3
| eval "2020-02 Actual"=2
| eval "2020-02 Forecast"=2
| eval "2020-03 Actual"=40
| eval "2020-03 Forecast"=23
]
| append
[| makeresults
| eval Country="SG"
| eval "2020-01 Actual"=2
| eval "2020-01 Forecast"=4
| eval "2020-02 Actual"=1
| eval "2020-02 Forecast"=9
| eval "2020-03 Actual"=30
| eval "2020-03 Forecast"=53 ]
| fields - _time
| eval prev=0
| foreach 20* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_DIFF='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' - prev|eval prev='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| fields - *Actual_DIFF,prev
| rename "* Forecast_DIFF" as "* Difference"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 13:04:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525054#M148128</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-10-16T13:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Foreach for multiple columns and multiple rows?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525855#M148412</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/136781"&gt;@renjith_nair&lt;/a&gt;&amp;nbsp;thanks for the answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 16:16:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-for-multiple-columns-and-multiple-rows/m-p/525855#M148412</guid>
      <dc:creator>ChioNeng</dc:creator>
      <dc:date>2020-10-21T16:16:27Z</dc:date>
    </item>
  </channel>
</rss>

