<?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: calculate average of last 30 days in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461976#M130229</link>
    <description>&lt;P&gt;i tried updating to be above code.however it does not seem to give me the correct value .The existing values are not returning after the change .&lt;/P&gt;

&lt;P&gt;index=MY_INDEX JOB=JOBNAME earliest= -30d@d latest= now()&lt;BR /&gt;
|dedup JOB,STATUS&lt;BR /&gt;
| eval startTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="RUNNING",strftime(_time, "%a %B %d %Y %H:%M:%S")),endTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="SUCCESS",strftime(_time, "%a %B %d %Y %H:%M:%S")), terminateTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="TERMINATED",strftime(_time, "%a %B %d %Y %H:%M:%S")) &lt;BR /&gt;
| eval sTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval eTime=strptime(endTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval tTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eventstats latest(STATUS) AS STATUS BY JOB &lt;BR /&gt;
| transaction JOB,startTime,endTime &lt;BR /&gt;
| eval e_Time=if(STATUS="TERMINATED" OR eTime&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 04:07:56 GMT</pubDate>
    <dc:creator>thomaap</dc:creator>
    <dc:date>2020-09-30T04:07:56Z</dc:date>
    <item>
      <title>calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461972#M130225</link>
      <description>&lt;P&gt;below average function is not giving me the correct value for last 30 days.Kindly advise&lt;/P&gt;

&lt;P&gt;| eval sTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval eTime=strptime(endTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval tTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eventstats latest(STATUS) AS STATUS BY JOB &lt;BR /&gt;
| transaction JOB,startTime,endTime &lt;BR /&gt;
| eval e_Time=if(STATUS="TERMINATED" OR eTime&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 13:14:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461972#M130225</guid>
      <dc:creator>thomaap</dc:creator>
      <dc:date>2020-02-05T13:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461973#M130226</link>
      <description>&lt;P&gt;I see no attempt to calculate an average in that SPL.  What field do you want to average?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 13:51:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461973#M130226</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-02-05T13:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461974#M130227</link>
      <description>&lt;P&gt;| eval stTime=strptime(startTime, "%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval edTime=strptime(e_Time, "%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval diff=edTime-stTime &lt;BR /&gt;
| eval diff= round(diff/60,2) &lt;BR /&gt;
| eval diff=edTime-stTime &lt;BR /&gt;
| eval diff= round(diff/60,2) &lt;BR /&gt;
| streamstats avg(diff) as average window=30 &lt;BR /&gt;
| eval avrg=round(average,2) &lt;BR /&gt;
looks like the entire query was not posted&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 14:21:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461974#M130227</guid>
      <dc:creator>thomaap</dc:creator>
      <dc:date>2020-02-05T14:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461975#M130228</link>
      <description>&lt;P&gt;The &lt;CODE&gt;streamstats avg(diff) as average window=30&lt;/CODE&gt; command will calculate the average diff over the previous 30 events, not necessarily 30 days.  Try this, instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;compute diff&amp;gt;
| bucket span=30d _time
| stats avg(diff) as average by _time
| eval avrg = round(average, 2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Feb 2020 15:20:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461975#M130228</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-02-05T15:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461976#M130229</link>
      <description>&lt;P&gt;i tried updating to be above code.however it does not seem to give me the correct value .The existing values are not returning after the change .&lt;/P&gt;

&lt;P&gt;index=MY_INDEX JOB=JOBNAME earliest= -30d@d latest= now()&lt;BR /&gt;
|dedup JOB,STATUS&lt;BR /&gt;
| eval startTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="RUNNING",strftime(_time, "%a %B %d %Y %H:%M:%S")),endTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="SUCCESS",strftime(_time, "%a %B %d %Y %H:%M:%S")), terminateTime= case("0"!=(strftime(_time, "%a %B %d %Y %H:%M:%S")) AND STATUS="TERMINATED",strftime(_time, "%a %B %d %Y %H:%M:%S")) &lt;BR /&gt;
| eval sTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval eTime=strptime(endTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eval tTime=strptime(startTime,"%a %B %d %Y %H:%M:%S") &lt;BR /&gt;
| eventstats latest(STATUS) AS STATUS BY JOB &lt;BR /&gt;
| transaction JOB,startTime,endTime &lt;BR /&gt;
| eval e_Time=if(STATUS="TERMINATED" OR eTime&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:07:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461976#M130229</guid>
      <dc:creator>thomaap</dc:creator>
      <dc:date>2020-09-30T04:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: calculate average of last 30 days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461977#M130230</link>
      <description>&lt;P&gt;That's the nature of &lt;CODE&gt;stats&lt;/CODE&gt;, which seemed fine since your question asked about calculating average and said nothing about preserving other values.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 15:53:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-average-of-last-30-days/m-p/461977#M130230</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-02-06T15:53:09Z</dc:date>
    </item>
  </channel>
</rss>

