<?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: Can you help me compare two fields with numeric values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387987#M113151</link>
    <description>&lt;P&gt;Do not use field names that start with numbers; these are &lt;CODE&gt;unclean&lt;/CODE&gt; and reserved namespaces.  Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cisco sourcetype=rcd earliest=-20m@m latest=-5m@m
| bucket _time span=5m 
| stats latest(Variable10) as Variable10 by _time Variable2 
| stats count(eval(like(Variable10,"Tx%|NS|%"))) as NS_Count by _time
| streamstats count as pri_key
| streamstats avg(NS_Count) as avg, stdev(NS_Count) as stdev
| eval avg=round(avg,2)
| eval stdev=round(stdev,2)
| eval lowerBound=(avg-stdev*2)
| eval upperBound=(avg+stdev*2)
| eval time_5m_value=if(pri_key=4,'NS_Count',"")
| eval time_15m_prev_upperBound=if(pri_key=3,'upperBound',"")
| eval time_15m_prev_lowerBound=if(pri_key=3,'lowerBound',"")
| eval time_15m_prev_avg=if(pri_key=3,'avg',"")
| eval time_15m_prev_stdev=if(pri_key=3,'stdev',"")
| stats values(time_5m_value) AS time_5m_value values(time_15m_prev_upperBound) AS time_15m_prev_upperBound values(time_15m_prev_lowerBound) AS time_15m_prev_lowerBound values(time_15m_prev_avg) AS time_15m_prev_avg values(time_15m_prev_stdev) AS time_15m_prev_stdev
| eval isTrue=if(time_5m_value &amp;gt; time_15m_prev_upperBound, 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Feb 2019 07:09:29 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-02-14T07:09:29Z</dc:date>
    <item>
      <title>Can you help me compare two fields with numeric values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387986#M113150</link>
      <description>&lt;P&gt;I have a query where I do a bunch of computations, and then at the end of it, I want to add a new field based on the result of a comparison of the numeric values of 2 other fields. Here is that eval statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval isTrue=if('5m_value'&amp;gt;'15m_prev_upperBound', 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;'isTrue field'  is always assigned 0 regardless of whether field '5m_value' is greater than or not than '15m_prev_upperBound' field! I don't know what I am doing wrong. I tried using case in the eval, but I still get the same results. &lt;/P&gt;

&lt;P&gt;FULL QUERY:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=cisco sourcetype=rcd earliest=-20m@m latest=-5m@m
    | bucket _time span=5m 
    | stats latest(Variable10) as Variable10 by _time Variable2 
    | stats count(eval(like(Variable10,"Tx%|NS|%"))) as NS_Count by _time
    | streamstats count as pri_key
    | streamstats avg(NS_Count) as avg, stdev(NS_Count) as stdev
    | eval avg=round(avg,2)
    | eval stdev=round(stdev,2)
    | eval lowerBound=(avg-stdev*2)
    | eval upperBound=(avg+stdev*2)
    | eval 5m_value=if(pri_key=4,'NS_Count',"")
    | eval 15m_prev_upperBound=if(pri_key=3,'upperBound',"")
    | eval 15m_prev_lowerBound=if(pri_key=3,'lowerBound',"")
    | eval 15m_prev_avg=if(pri_key=3,'avg',"")
    | eval 15m_prev_stdev=if(pri_key=3,'stdev',"")
    | stats values(5m_value) as 5m_value values(15m_prev_upperBound) as 15m_prev_upperBound values(15m_prev_lowerBound) as 15m_prev_lowerBound values(15m_prev_avg) as 15m_prev_avg values(15m_prev_stdev) as 15m_prev_stdev
    | eval isTrue=if('5m_value'&amp;gt;'15m_prev_upperBound', 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:16:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387986#M113150</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T23:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two fields with numeric values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387987#M113151</link>
      <description>&lt;P&gt;Do not use field names that start with numbers; these are &lt;CODE&gt;unclean&lt;/CODE&gt; and reserved namespaces.  Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=cisco sourcetype=rcd earliest=-20m@m latest=-5m@m
| bucket _time span=5m 
| stats latest(Variable10) as Variable10 by _time Variable2 
| stats count(eval(like(Variable10,"Tx%|NS|%"))) as NS_Count by _time
| streamstats count as pri_key
| streamstats avg(NS_Count) as avg, stdev(NS_Count) as stdev
| eval avg=round(avg,2)
| eval stdev=round(stdev,2)
| eval lowerBound=(avg-stdev*2)
| eval upperBound=(avg+stdev*2)
| eval time_5m_value=if(pri_key=4,'NS_Count',"")
| eval time_15m_prev_upperBound=if(pri_key=3,'upperBound',"")
| eval time_15m_prev_lowerBound=if(pri_key=3,'lowerBound',"")
| eval time_15m_prev_avg=if(pri_key=3,'avg',"")
| eval time_15m_prev_stdev=if(pri_key=3,'stdev',"")
| stats values(time_5m_value) AS time_5m_value values(time_15m_prev_upperBound) AS time_15m_prev_upperBound values(time_15m_prev_lowerBound) AS time_15m_prev_lowerBound values(time_15m_prev_avg) AS time_15m_prev_avg values(time_15m_prev_stdev) AS time_15m_prev_stdev
| eval isTrue=if(time_5m_value &amp;gt; time_15m_prev_upperBound, 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 07:09:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387987#M113151</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-14T07:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two fields with numeric values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387988#M113152</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/166308"&gt;@mmdacutanan&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;I'm not entirely sure. My first thought is this:&lt;/P&gt;

&lt;P&gt;"| stats values(5m_value) as 5m_value" will give you a multivalue field. I don't how the exact behavior on how Splunk compares (via &amp;gt;) multivalue fields.&lt;/P&gt;

&lt;P&gt;So I suppose you want single values instead of mutlivalues. You could try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats first(5m_value) as 5m_value first(time_15m_prev_upperBound) AS time_15m_prev_upperBound
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:14:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387988#M113152</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2020-09-29T23:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me compare two fields with numeric values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387989#M113153</link>
      <description>&lt;P&gt;Thank you so so much for the awesome tip. I tried what you gave and at first it didn't work. Then I simplified the name even more (took out the underscore) and that did the trick! So the last 2 lines look like this now:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(time_5m_value) AS FiveMinCount values(time_15m_prev_upperBound) AS Prev15mUprBnd values(time_15m_prev_lowerBound) AS time_15m_prev_lowerBound values(time_15m_prev_avg) AS time_15m_prev_avg values(time_15m_prev_stdev) AS time_15m_prev_stdev
| eval isTrue=if("FiveMinCount"&amp;gt;"Prev15mUprBnd", 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 08:15:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-compare-two-fields-with-numeric-values/m-p/387989#M113153</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2019-02-14T08:15:35Z</dc:date>
    </item>
  </channel>
</rss>

