<?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: Creating an If statement in Search with max() function inside in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331548#M98635</link>
    <description>&lt;P&gt;@somesoni2 - &lt;/P&gt;

&lt;P&gt;Whenever someone formats a date... &lt;/P&gt;

&lt;P&gt;...before grouping... &lt;/P&gt;

&lt;P&gt;...without a format like "%Y-%m-%d" that will sort into the right order....&lt;/P&gt;

&lt;P&gt;...puppies and kittens cry. &lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2017 20:54:23 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-27T20:54:23Z</dc:date>
    <item>
      <title>Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331540#M98627</link>
      <description>&lt;P&gt;Here's what I have below. I'm trying to do unit conversion and the unit trails in the string (ex. 127 KiB). Any ideas as to why the statement won't work?&lt;/P&gt;

&lt;P&gt;eval new_max_rx = if(rx_today = "*KiB", "max(rx_today)*0.000976562") | timechart new_max_rx, max(tx_today) | rename new_max_rx as "Received Data since 12:00 AM", max(tx_today) as "Transmitted Data since 12:00 AM"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:04:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331540#M98627</guid>
      <dc:creator>aracer</dc:creator>
      <dc:date>2020-09-29T15:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331541#M98628</link>
      <description>&lt;P&gt;&lt;CODE&gt;max()&lt;/CODE&gt; is not a standalone function in splunk.  It is an aggregate function that is only valid in the context of a grouping calculation like &lt;CODE&gt;stats&lt;/CODE&gt;, &lt;CODE&gt;chart&lt;/CODE&gt; or &lt;CODE&gt;timechart&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;Therefore, you need to calculate it beforehand.  &lt;/P&gt;

&lt;P&gt;I believe what you want is &lt;CODE&gt;eventstats&lt;/CODE&gt;, but there are some other syntax mistakes, so you need to show us the earlier portion of the search so we can straighten it all out for you.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 14:54:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331541#M98628</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-27T14:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331542#M98629</link>
      <description>&lt;P&gt;Thank you for the speedy response! This is all there is to my search besides specifying the file I'm looking at. &lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 15:12:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331542#M98629</guid>
      <dc:creator>aracer</dc:creator>
      <dc:date>2017-07-27T15:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331543#M98630</link>
      <description>&lt;P&gt;Could you explain more about what &lt;CODE&gt;max(rx_today)&lt;/CODE&gt; should capture in the eval? Is it max value of rx_today for that day?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 15:51:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331543#M98630</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-27T15:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331544#M98631</link>
      <description>&lt;P&gt;Yes, it is the max value for that day&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 16:18:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331544#M98631</guid>
      <dc:creator>aracer</dc:creator>
      <dc:date>2017-07-27T16:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331545#M98632</link>
      <description>&lt;P&gt;As @Daljeanis suggested, you'd need to add eventstats (with few other elements) to do that. Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...your base search
eval day=strftime(_time,"%m/%d/%Y") | eventstats max(rx_today) as max_rx_today by day
|eval new_max_rx = if(rx_today = "*KiB", "max_rx_today*0.000976562") | timechart max(new_max_rx) as "Received Data since 12:00 AM", max(tx_today) as "Transmitted Data since 12:00 AM"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 16:27:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331545#M98632</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-27T16:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331546#M98633</link>
      <description>&lt;P&gt;@DalJeanis, there is a possibility that there is an aggregate statistical function prior to the code snippet which is calculating &lt;CODE&gt;max(rx_today)&lt;/CODE&gt; without renaming the same.&lt;/P&gt;

&lt;P&gt;I see issue with the if condition for pattern match. Following eval with &lt;CODE&gt;match()&lt;/CODE&gt; should do the needful and for using if condition else block should be used, for which I have used rx_today.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval new_max_rx = if(match(rx_today,"KiB"),'max(rx_today)'*0.000976562,rx_today)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: It is a good habit to rename/alias fields after aggregating functions for example &lt;CODE&gt;| timechart max(rx_today) as max_rx_today&lt;/CODE&gt;, to ensure that special characters are not included in the field name and it is more meaningful.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 16:27:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331546#M98633</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-27T16:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331547#M98634</link>
      <description>&lt;P&gt;Thank you @niketnilay - that solved my issue!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 20:28:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331547#M98634</guid>
      <dc:creator>aracer</dc:creator>
      <dc:date>2017-07-27T20:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331548#M98635</link>
      <description>&lt;P&gt;@somesoni2 - &lt;/P&gt;

&lt;P&gt;Whenever someone formats a date... &lt;/P&gt;

&lt;P&gt;...before grouping... &lt;/P&gt;

&lt;P&gt;...without a format like "%Y-%m-%d" that will sort into the right order....&lt;/P&gt;

&lt;P&gt;...puppies and kittens cry. &lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 20:54:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331548#M98635</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-27T20:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an If statement in Search with max() function inside</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331549#M98636</link>
      <description>&lt;P&gt;Glad it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 20:55:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-an-If-statement-in-Search-with-max-function-inside/m-p/331549#M98636</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-27T20:55:01Z</dc:date>
    </item>
  </channel>
</rss>

