<?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 check which value is larger than the other and calculate the gap between them? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445874#M126504</link>
    <description>&lt;P&gt;it is exactly what i did and said that gap is empty &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 14:49:21 GMT</pubDate>
    <dc:creator>sarit_s</dc:creator>
    <dc:date>2019-03-20T14:49:21Z</dc:date>
    <item>
      <title>How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445870#M126500</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I have two values that i need to check which one of them is bigger and calculate the gap between them &lt;BR /&gt;
how can i do it ?&lt;BR /&gt;
i tried this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "Current temp Front block = (?&amp;lt;Front&amp;gt;.+)" | rex "Current temp Rear block = (?&amp;lt;Rear&amp;gt;.+)"|eval gap=coalesce(Front&amp;gt;Rear, Front-Rear, Rear-Front) |table Front Rear gap
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But gap is returning empty&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:32:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445870#M126500</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T14:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445871#M126501</link>
      <description>&lt;P&gt;If you don't mind (possible) negative values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "Current temp Front block = (?&amp;lt;Front&amp;gt;.+)" | rex "Current temp Rear block = (?&amp;lt;Rear&amp;gt;.+)"|eval delta=Front-Rear |table Front Rear delta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you don't want negative values, use this for delta:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval delta=case(Front&amp;gt;Rear, Front-Rear, Front&amp;lt;Rear,Rear-Front,Front==Rear,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:40:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445871#M126501</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T14:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445872#M126502</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;....|eval gap=if(Front&amp;gt;Rear, Front-Rear, Rear-Front) |table Front Rear gap
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:44:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445872#M126502</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-03-20T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445873#M126503</link>
      <description>&lt;P&gt;delta is empty&lt;/P&gt;

&lt;P&gt;this is how the table looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Front   Rear    delta
  2789       
            2797     
  2788       
            2797     
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:48:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445873#M126503</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T14:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445874#M126504</link>
      <description>&lt;P&gt;it is exactly what i did and said that gap is empty &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:49:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445874#M126504</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T14:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445875#M126505</link>
      <description>&lt;P&gt;Are the values numeric??&lt;BR /&gt;
What values does the table produce for Front and Rear?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445875#M126505</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T14:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445876#M126506</link>
      <description>&lt;P&gt;i pasted an example of the data&lt;BR /&gt;
the values are numeric&lt;/P&gt;

&lt;P&gt;for example :&lt;BR /&gt;
Front = 2789&lt;BR /&gt;
Rear = 2797&lt;/P&gt;

&lt;P&gt;maybe the problem is that each raw in the table contains only one of the values ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Front   Rear    delta
  2789       
          2797   
  2788       
          2797   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:01:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445876#M126506</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T15:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445877#M126507</link>
      <description>&lt;P&gt;Oh, they are separate events! that's why.&lt;BR /&gt;
Is there anything common to both events which relates them?&lt;BR /&gt;
Something like a host/device name or ID?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:05:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445877#M126507</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T15:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445878#M126508</link>
      <description>&lt;P&gt;i can extract SerialNumber&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:07:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445878#M126508</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T15:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445879#M126509</link>
      <description>&lt;P&gt;also, i have this 2 values every minute, i need to check the gap for each minute so if:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   SerialNumber    Front   Rear    delta
2019-03-07 11:17:26 570123    2789       
2019-03-07 11:17:26 570123        2797   
2019-03-07 11:16:26 570123    2788       
2019-03-07 11:16:26 570123        2797   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i will have to check it once for 11:17 and once for 11:16&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445879#M126509</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T15:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445880#M126510</link>
      <description>&lt;P&gt;Try this &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex "Current temp Front block = (?&amp;lt;Front&amp;gt;.+)" | rex "Current temp Rear block = (?&amp;lt;Rear&amp;gt;.+)"|timechart last(Front) as Front last(Rear) as Rear span=1m|eval delta=case(Front&amp;gt;Rear, Front-Rear, Front&amp;lt;Rear,Rear-Front,Front==Rear,0)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:28:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445880#M126510</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T15:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445881#M126511</link>
      <description>&lt;P&gt;this is the error i get:&lt;/P&gt;

&lt;P&gt;The specified span would result in too many (&amp;gt;50000) rows. &lt;/P&gt;

&lt;P&gt;and also delta is still empty and SerialNumber got empty and the timestamp become without hour:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   SerialNumber    Front   Rear    delta
2019-01-23        2781    2791   
2019-01-24        2857    2865   
2019-01-25        2760    2769 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 17:32:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445881#M126511</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-20T17:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445882#M126512</link>
      <description>&lt;P&gt;Because you have your values in different events you need to combine them into one event somehow&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=12 
| eval SerialNumber="thesameserial1234" 
| streamstats count 
| eval _time=_time+(floor(count/2))*60
| eval Front=if(count%2=0, null(), count) 
| eval Rear=if(count%2=0, count, null()) 
| bin _time span=1m 
| stats values(Front) AS Front values(Rear) AS Rear BY _time SerialNumber 
| eval gap=abs(Front-Rear)

| makeresults count=12 
| eval SerialNumber="thesameserial1234" 
| streamstats count 
| eval _time=_time+(floor(count/2))*60
| eval Front=if(count%2=0, null(), count) 
| eval Rear=if(count%2=0, count, null()) 
| transaction maxspan=1m  _time SerialNumber
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Mar 2019 09:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445882#M126512</guid>
      <dc:creator>mhoogcarspel_sp</dc:creator>
      <dc:date>2019-03-24T09:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445883#M126513</link>
      <description>&lt;P&gt;this is the result i got :&lt;BR /&gt;
    Front   Rear    _raw    _time   closed_txn  count   duration    eventcount  field_match_sum linecount&lt;BR /&gt;
        12      2019-03-24 16:28:11 0   12  0   1   1   1&lt;BR /&gt;
    11  10&lt;BR /&gt;&lt;BR /&gt;
    2019-03-24 16:27:11 0&lt;BR /&gt;&lt;BR /&gt;
    10&lt;BR /&gt;
    11&lt;BR /&gt;
    0   2   2   2&lt;BR /&gt;
    9   8&lt;BR /&gt;&lt;BR /&gt;
    2019-03-24 16:26:11 0&lt;BR /&gt;&lt;BR /&gt;
    8&lt;BR /&gt;
    9&lt;BR /&gt;
    0   2   2   2&lt;BR /&gt;
    7   6&lt;BR /&gt;&lt;BR /&gt;
    2019-03-24 16:25:11 0&lt;BR /&gt;&lt;BR /&gt;
    6&lt;BR /&gt;
    7&lt;BR /&gt;
    0   2   2   2&lt;/P&gt;

&lt;P&gt;no idea what is going on there &lt;BR /&gt;
maybe you can explain to me the search command ?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:48:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445883#M126513</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2020-09-29T23:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445884#M126514</link>
      <description>&lt;P&gt;do you have any idea how to solve it ?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 11:51:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445884#M126514</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-27T11:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445885#M126515</link>
      <description>&lt;P&gt;Assuming you have serialnumber, Front and Rear extracted, just add the following to your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats max(Front) as Front max(Rear) as Rear by _time,serialnumber | eval delta=abs(Front-Rear)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The stats command combines the two rows with same time and serialnumber, the eval calculates the delta (using abs, so result is always positive and you don't need to first check which one is bigger).&lt;/P&gt;

&lt;P&gt;A search incl. your sample data to demonstrate it works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval serialnumber=570123 | eval Front=2788
| append [ | makeresults | eval serialnumber=570123 | eval Rear=2797  ]
| append [ | makeresults | eval serialnumber=570123 | eval Front=2789 | eval _time=_time+60  ]
| append [ | makeresults | eval serialnumber=570123 | eval Rear=2797 | eval _time=_time+60  ]
| stats max(Front) as Front max(Rear) as Rear by _time,serialnumber | eval delta=abs(Front-Rear)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 13:27:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445885#M126515</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-27T13:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445886#M126516</link>
      <description>&lt;P&gt;delta is still empty &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time               SerialNumber  Front  Rear                 delta
2019-01-23 11:48:18 570123    2776    2766   
2019-01-23 11:49:18 570123    2948    2941   
2019-01-23 11:50:19 570123    2940    2938   
2019-01-23 11:51:19 570123    2930    2934   
2019-01-23 11:52:20 570123    2921    2931   
2019-01-23 11:53:20 570123    2912    2925   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 13:39:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445886#M126516</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-27T13:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445887#M126517</link>
      <description>&lt;P&gt;If merging the rows using the stats command works as expected (which your sample output seems to suggest), then there is no reason that eval part wouldn't work. Can you perhaps post a screenshot that shows the query and the output (mask sensitive details if needed)?&lt;/P&gt;

&lt;P&gt;Unless the way you extract the Front and Rear values causes those fields to contain whitespace (which means they are not numeric). Perhaps change the &lt;CODE&gt;.+&lt;/CODE&gt; in your regex to &lt;CODE&gt;\d+&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445887#M126517</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-27T14:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445888#M126518</link>
      <description>&lt;P&gt;unfortunately i don't have enough karma points to upload images&lt;BR /&gt;
but changing .+ to \d+ returning Front and Rear empty&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:08:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445888#M126518</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-03-27T14:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to check which value is larger than the other and calculate the gap between them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445889#M126519</link>
      <description>&lt;P&gt;You can always post a link to an image uploaded to some random imagehost &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;That seems to suggest the raw data perhaps contains more than 1 space before the number? Can you post some raw data? Or perhaps try this regex (similar for the other):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "Current temp Front block =\s+(?&amp;lt;Front&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:13:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-which-value-is-larger-than-the-other-and-calculate/m-p/445889#M126519</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-03-27T14:13:27Z</dc:date>
    </item>
  </channel>
</rss>

