<?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: Cannot use Var stats function within Eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Cannot-use-Var-stats-function-within-Eval/m-p/636988#M221191</link>
    <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; command works with a single result at a time.&amp;nbsp; Therefore, there is no variance in any of the fields.&amp;nbsp; That's why &lt;FONT face="courier new,courier"&gt;var&lt;/FONT&gt; is valid only in stats (and a few other commands, but not eva).&lt;/P&gt;</description>
    <pubDate>Sat, 01 Apr 2023 00:16:44 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2023-04-01T00:16:44Z</dc:date>
    <item>
      <title>Cannot use Var stats function within Eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-use-Var-stats-function-within-Eval/m-p/636984#M221187</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the following query:&lt;BR /&gt;| tstats count where index=dns earliest=-90d latest=now() groupby _time span=1d&lt;BR /&gt;| fields _time count&lt;BR /&gt;| rename _time as hour&lt;BR /&gt;| eval hour=strftime(hour,"%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| fields hour count&lt;BR /&gt;| fields - _*&lt;BR /&gt;| eventstats avg(count) as avg_count&lt;BR /&gt;| eval k=(pow(avg_count,2))/(var(count)-avg_count)&lt;BR /&gt;| eval outlier=if(count&amp;gt;(avg_count+k*pow(avg_count,2)),1,0)&lt;BR /&gt;| eval predicted_outlier=if(outlier=1,"anomaly","normal")&lt;BR /&gt;| eval actual_outlier=if(day&amp;gt;relative_time(now(),"-7d"), "anomaly", "normal")&lt;BR /&gt;| eval true_positives=if(predicted_outlier="anomaly" AND actual_outlier="anomaly", 1, 0)&lt;BR /&gt;| eval false_positives=if(predicted_outlier="anomaly" AND actual_outlier="normal", 1, 0)&lt;BR /&gt;| eval false_negatives=if(predicted_outlier="normal" AND actual_outlier="anomaly", 1, 0)&lt;BR /&gt;| eval true_negatives=if(predicted_outlier="normal" AND actual_outlier="normal", 1, 0)&lt;BR /&gt;| stats sum(true_positives) as TP, sum(false_positives) as FP, sum(false_negatives) as FN, sum(true_negatives) as TN&lt;BR /&gt;| eval accuracy=(TP+TN)/(TP+FP+FN+TN)&lt;BR /&gt;| eval precision=TP/(TP+FP)&lt;BR /&gt;| eval recall=TP/(TP+FN)&lt;BR /&gt;&lt;BR /&gt;However, the this statement is not working as the var command does not work without stats and I cannot use stats in a command by itself as I want to apply this k formula for each daily count. Can you please help?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 23:32:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-use-Var-stats-function-within-Eval/m-p/636984#M221187</guid>
      <dc:creator>POR160893</dc:creator>
      <dc:date>2023-03-31T23:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot use Var stats function within Eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-use-Var-stats-function-within-Eval/m-p/636988#M221191</link>
      <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; command works with a single result at a time.&amp;nbsp; Therefore, there is no variance in any of the fields.&amp;nbsp; That's why &lt;FONT face="courier new,courier"&gt;var&lt;/FONT&gt; is valid only in stats (and a few other commands, but not eva).&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2023 00:16:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-use-Var-stats-function-within-Eval/m-p/636988#M221191</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-04-01T00:16:44Z</dc:date>
    </item>
  </channel>
</rss>

