<?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: time frame calculation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483200#M193299</link>
    <description>&lt;P&gt;let's suppose you want a count and average &lt;CODE&gt;Value&lt;/CODE&gt; of all the records that match some criteria in the 30 days prior to the end of a report.  You can do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets all your data 
| addinfo
| eval last30daysFlag=case(if _time&amp;gt;info_max_time - 30*1440, "Y") 
| eval my30dayCount=case(last30daysFlag="Y", 1) 
| eval my30dayValue=case(last30daysFlag="Y", Value) 
| eventstats sum(my30dayCount) as my30dayCount avg(my30dayValue) as my30dayValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That can also be written more succinctly as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets all your data 
| addinfo
| stats sum(eval(case(_time&amp;gt;info_max_time - 30*1440,1))) as my30dayCount,
            avg(eval(case(_time&amp;gt;info_max_time - 30*1440,Value))) as my30dayValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In both cases, by using &lt;CODE&gt;eventstats&lt;/CODE&gt;, the answers for the whole search will be added to every record.  &lt;/P&gt;

&lt;P&gt;If the entire search is using a stats command, you could also build it into that instead of using &lt;CODE&gt;eventstats&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2020 17:50:45 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2020-04-28T17:50:45Z</dc:date>
    <item>
      <title>time frame calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483198#M193297</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;
i want to write IF statement as part of my query and want it to run on time frame of 30 days or more... &lt;BR /&gt;
the query itself runs on time frame of "all time" but the result i want is from 30 days or more&lt;/P&gt;

&lt;P&gt;how can i do it ?&lt;/P&gt;

&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 07:22:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483198#M193297</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2020-04-26T07:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: time frame calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483199#M193298</link>
      <description>&lt;P&gt;Please describe the problem you are trying to solve.  What queries have you tried?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 14:49:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483199#M193298</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-04-26T14:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: time frame calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483200#M193299</link>
      <description>&lt;P&gt;let's suppose you want a count and average &lt;CODE&gt;Value&lt;/CODE&gt; of all the records that match some criteria in the 30 days prior to the end of a report.  You can do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets all your data 
| addinfo
| eval last30daysFlag=case(if _time&amp;gt;info_max_time - 30*1440, "Y") 
| eval my30dayCount=case(last30daysFlag="Y", 1) 
| eval my30dayValue=case(last30daysFlag="Y", Value) 
| eventstats sum(my30dayCount) as my30dayCount avg(my30dayValue) as my30dayValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That can also be written more succinctly as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search that gets all your data 
| addinfo
| stats sum(eval(case(_time&amp;gt;info_max_time - 30*1440,1))) as my30dayCount,
            avg(eval(case(_time&amp;gt;info_max_time - 30*1440,Value))) as my30dayValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In both cases, by using &lt;CODE&gt;eventstats&lt;/CODE&gt;, the answers for the whole search will be added to every record.  &lt;/P&gt;

&lt;P&gt;If the entire search is using a stats command, you could also build it into that instead of using &lt;CODE&gt;eventstats&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 17:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-frame-calculation/m-p/483200#M193299</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-04-28T17:50:45Z</dc:date>
    </item>
  </channel>
</rss>

