<?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 How to find the field value corresponding to an extremity (min, max)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225132#M66382</link>
    <description>&lt;P&gt;Say I have sales figures&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  Month   Sales
  June      44
  July      55
  August    66
  September 60
  November  50
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I know that August is the month when sales maximized?  This seems to be a common operation, but I can't find an easy function to call.&lt;/P&gt;

&lt;P&gt;All I can come up with is a convoluted manipulation, like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats max(Sales) as maxSales
| eval maxMonth=if(Sales==maxSales,Month,null)
| stats max(maxSales) values(maxMonth)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(It is OK if two field values match.)&lt;/P&gt;

&lt;P&gt;As this is just a small part of a more complex operation, it feels awkward to do all these just to find peak value of an associated field.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Nov 2015 21:28:24 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2015-11-11T21:28:24Z</dc:date>
    <item>
      <title>How to find the field value corresponding to an extremity (min, max)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225132#M66382</link>
      <description>&lt;P&gt;Say I have sales figures&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  Month   Sales
  June      44
  July      55
  August    66
  September 60
  November  50
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I know that August is the month when sales maximized?  This seems to be a common operation, but I can't find an easy function to call.&lt;/P&gt;

&lt;P&gt;All I can come up with is a convoluted manipulation, like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats max(Sales) as maxSales
| eval maxMonth=if(Sales==maxSales,Month,null)
| stats max(maxSales) values(maxMonth)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(It is OK if two field values match.)&lt;/P&gt;

&lt;P&gt;As this is just a small part of a more complex operation, it feels awkward to do all these just to find peak value of an associated field.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2015 21:28:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225132#M66382</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2015-11-11T21:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the field value corresponding to an extremity (min, max)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225133#M66383</link>
      <description>&lt;P&gt;The easiest way is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | sort - Sales | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But you probably need all the events so try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eventstats max(Sales) as maxSales
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then maybe after that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | where Sales=maxSales | table Month
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval MaxSalesMonth = if((Sales==maxSales), "Yes", "No")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Nov 2015 22:01:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225133#M66383</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-11T22:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the field value corresponding to an extremity (min, max)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225134#M66384</link>
      <description>&lt;P&gt;Yes, I am looking to keep all events, so &lt;CODE&gt;head&lt;/CODE&gt; and &lt;CODE&gt;where&lt;/CODE&gt; do not apply.  the last one is the same as the one I posted in the question, which I feel convoluted, as the number of events involved are numerous.  I need the associated value(s) only as a quick reference in a complex scheduled search that already uses lots of stats manipulations.&lt;/P&gt;

&lt;P&gt;Of course, if there is no better way, I'll have to take what I get.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2015 22:31:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/225134#M66384</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2015-11-11T22:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the field value corresponding to an extremity (min, max)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/649672#M224631</link>
      <description>&lt;P&gt;Now that I'm more comfortable with SPL, I can think of a few more alternatives. &amp;nbsp;This one is the cleanest yet&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats max(eval(printf("%06d", Sales) . ":" . Month)) as sales_max
| eval maxMonth = replace(sales_max, "^\d+:", "")&lt;/LI-CODE&gt;&lt;P&gt;The advantage here is that every event gets maxMonth without doing another stats operation. Caveat: If there are multiple maxima in the numeric field, it will pick the one with the highest ASCII value of the other field. (In most applications this is acceptable.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 18:06:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-field-value-corresponding-to-an-extremity-min/m-p/649672#M224631</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-07-07T18:06:59Z</dc:date>
    </item>
  </channel>
</rss>

