<?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: Difference between rows of query result in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378383#M110913</link>
    <description>&lt;P&gt;@reverse try the following run anywhere example which prepares data similar to your question. from &lt;CODE&gt;|makeresults&lt;/CODE&gt; till &lt;CODE&gt;| fields - data count&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="Jan-1 100 60 87 78 86 545 53 509 56 545 656;Jan-2 110 60 87 78 86 545 53 509 56 545 656;Jan-3 111 60 87 78 86 545 53 509 56 545 655;Jan-4 112 60 89 78 86 545 53 509 56 545 656"
| makemv data delim=";"
| stats count by data
| makemv data delim=" "
| eval date=mvindex(data,0),
       field1=mvindex(data,1),
       field2=mvindex(data,2),
       field3=mvindex(data,3),
       field4=mvindex(data,4),
       field5=mvindex(data,5),
       field6=mvindex(data,6),
       field7=mvindex(data,7),
       field8=mvindex(data,8),
       field9=mvindex(data,9),
       field10=mvindex(data,10)
| fields - data count

| fields - date
| stats first(*) as first* last(*) as last*
| foreach first* [| eval diff_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=first&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;-last&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;]
| fields diff_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then the remaining command calculate difference as per your requirement. Since you have not provided field names I have cooked up all of it as field1, field2 etc.&lt;/P&gt;</description>
    <pubDate>Sat, 18 May 2019 16:57:20 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-05-18T16:57:20Z</dc:date>
    <item>
      <title>Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378377#M110907</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Jan-1 100 60 87 78 86 545 53 509 56 545 656
Jan2  110 60 87 78 86 545 53 509 56 545 656
Jan-3 111 60 87 78 86 545 53 509 56 545 655
Jan-4 112 60 89 78 86 545 53 509 56 545 656
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;CODE&gt;diff 2 0 2 0 ....&lt;/CODE&gt;&lt;/STRONG&gt;&lt;BR /&gt;
I have to compute "always" the difference between last row and first row ( diff)&lt;BR /&gt;
How can I achieve this ?&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 00:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378377#M110907</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-18T00:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378378#M110908</link>
      <description>&lt;P&gt;results would be dynamic.. first column&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 02:08:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378378#M110908</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-18T02:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378379#M110909</link>
      <description>&lt;P&gt;@reverse please add more details to your problem. For the data provided what is the output you need?&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 14:07:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378379#M110909</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-18T14:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378380#M110910</link>
      <description>&lt;P&gt;diff is the output&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 14:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378380#M110910</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-18T14:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378381#M110911</link>
      <description>&lt;P&gt;@reverse the number of rows is it fixed or can it vary? Also once you have the difference do you want to output only the difference?&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 16:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378381#M110911</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-18T16:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378382#M110912</link>
      <description>&lt;P&gt;Rows will vary as per timepicker range .. last 7 days 30 days .. so on .. columns are fixed though&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 16:48:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378382#M110912</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-18T16:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378383#M110913</link>
      <description>&lt;P&gt;@reverse try the following run anywhere example which prepares data similar to your question. from &lt;CODE&gt;|makeresults&lt;/CODE&gt; till &lt;CODE&gt;| fields - data count&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="Jan-1 100 60 87 78 86 545 53 509 56 545 656;Jan-2 110 60 87 78 86 545 53 509 56 545 656;Jan-3 111 60 87 78 86 545 53 509 56 545 655;Jan-4 112 60 89 78 86 545 53 509 56 545 656"
| makemv data delim=";"
| stats count by data
| makemv data delim=" "
| eval date=mvindex(data,0),
       field1=mvindex(data,1),
       field2=mvindex(data,2),
       field3=mvindex(data,3),
       field4=mvindex(data,4),
       field5=mvindex(data,5),
       field6=mvindex(data,6),
       field7=mvindex(data,7),
       field8=mvindex(data,8),
       field9=mvindex(data,9),
       field10=mvindex(data,10)
| fields - data count

| fields - date
| stats first(*) as first* last(*) as last*
| foreach first* [| eval diff_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=first&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;-last&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;]
| fields diff_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then the remaining command calculate difference as per your requirement. Since you have not provided field names I have cooked up all of it as field1, field2 etc.&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 16:57:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378383#M110913</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-18T16:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378384#M110914</link>
      <description>&lt;P&gt;it worked.. thanks! how can i show &lt;STRONG&gt;only&lt;/STRONG&gt; that data where &lt;EM&gt;diff was maximum&lt;/EM&gt;... like top 2.. I know it is complex&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 17:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378384#M110914</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-18T17:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378385#M110915</link>
      <description>&lt;P&gt;how can i show only that data where diff was maximum... like top 2..&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 03:15:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378385#M110915</guid>
      <dc:creator>reverse</dc:creator>
      <dc:date>2019-05-19T03:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between rows of query result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378386#M110916</link>
      <description>&lt;P&gt;@reverse try appending the following to your existing search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transpose 0 column_name=difference
| sort 0 - "row 1"
| head 2
| transpose header_field=difference
| fields diff_*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 May 2019 17:25:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Difference-between-rows-of-query-result/m-p/378386#M110916</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-05-19T17:25:24Z</dc:date>
    </item>
  </channel>
</rss>

