<?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: if-else statement with timeframe in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418267#M73784</link>
    <description>&lt;P&gt;If your base search only includes metadata fields (host/index/source/sourcetype ) or any index-time extracted fields, you can run something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar  [| tstats count WHERE index=foo sourcetype=bar earliest=@mon | eval earliest=if(count=0,"-1mon@mon","@mon") | table earliest ] |....rest of the search
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 02 Jul 2018 18:31:30 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-07-02T18:31:30Z</dc:date>
    <item>
      <title>if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418263#M73780</link>
      <description>&lt;P&gt;I would like to specify my search to return a previous months + the current months data if the count outputted by just the current months data is less than 0. How would I do that?&lt;/P&gt;

&lt;P&gt;Right now I have earliest = @mon for the current months data. How do I implement the if else statement?&lt;/P&gt;

&lt;P&gt;I have this right now. Would this be in the first pipe?&lt;BR /&gt;
eval (if count(data) &amp;lt;=0, earliest= -1mon@mon, else earliest=@mon )&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 15:15:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418263#M73780</guid>
      <dc:creator>shreyad</dc:creator>
      <dc:date>2018-07-02T15:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418264#M73781</link>
      <description>&lt;P&gt;What search are you running? &lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 18:11:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418264#M73781</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-07-02T18:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418265#M73782</link>
      <description>&lt;P&gt;@shreyad, what have you tried so far? Also what does the base search looks like for you? Is it based on only metadata fields like index sourcetype etc. or does it involve other Search Time extracted fields as well.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 18:12:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418265#M73782</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-07-02T18:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418266#M73783</link>
      <description>&lt;P&gt;There is an index, sourcetype and host. All I have tried is what I posted and "earliest = @mon." But that does not solve my issue of wanting to output the previous months data iff the count of the current month is &amp;lt;=0.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 18:17:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418266#M73783</guid>
      <dc:creator>shreyad</dc:creator>
      <dc:date>2018-07-02T18:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418267#M73784</link>
      <description>&lt;P&gt;If your base search only includes metadata fields (host/index/source/sourcetype ) or any index-time extracted fields, you can run something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar  [| tstats count WHERE index=foo sourcetype=bar earliest=@mon | eval earliest=if(count=0,"-1mon@mon","@mon") | table earliest ] |....rest of the search
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jul 2018 18:31:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418267#M73784</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-07-02T18:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418268#M73785</link>
      <description>&lt;P&gt;A count cannot be less than zero.  What are you trying to achieve?&lt;/P&gt;

&lt;P&gt;In general, my approach would be to calculate the two items, then throw away the unwanted if the test is not met.  &lt;CODE&gt;Eventstats&lt;/CODE&gt; is useful for generating aggregations for that test.  Here's one way to do that, in pseudocode...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that gets all the data
 | eval  myflag= if (the event is this month,"Now","Before")
 | eventstats ... some aggregate command that adds up whatever you want to test for this month...
 | where myflag="Before" OR some test on the aggregate
 | the rest of your logic
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you only want the aggregated data, then use an actual &lt;CODE&gt;stats&lt;/CODE&gt; command instead of &lt;CODE&gt;eventstats&lt;/CODE&gt;, and add &lt;CODE&gt;myflag&lt;/CODE&gt; as one of the group by fields. &lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 22:13:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418268#M73785</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-07-02T22:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: if-else statement with timeframe</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418269#M73786</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Index=YouShouldAlwaysSpeciryINdex AND sourcetype=AndSourcetypeToo AND other stuff here
earliest = -1mon@mon latest=@s
| bucket _time span=1mon
| stats sum(YourFieldWithValuesHere) AS monthlyCount BY _time
| transpose
| tail 1
| eval count = if('row 2' &amp;lt;=0, 'row 1', 'row 2')
| table count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 15:57:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/if-else-statement-with-timeframe/m-p/418269#M73786</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-06T15:57:16Z</dc:date>
    </item>
  </channel>
</rss>

