<?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 Group by oldest Date in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82434#M20934</link>
    <description>&lt;P&gt;Search:&lt;BR /&gt;
stats count by filingType, application, recDate &lt;/P&gt;

&lt;P&gt;filingType      application     recDate     count &lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-03-31  1&lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-04-01      2&lt;/P&gt;

&lt;P&gt;I need to group by oldest recDate so results look like this:&lt;/P&gt;

&lt;P&gt;filingType      application     recDate     count&lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-03-31  3&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2013 18:38:44 GMT</pubDate>
    <dc:creator>anava</dc:creator>
    <dc:date>2013-04-02T18:38:44Z</dc:date>
    <item>
      <title>Group by oldest Date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82434#M20934</link>
      <description>&lt;P&gt;Search:&lt;BR /&gt;
stats count by filingType, application, recDate &lt;/P&gt;

&lt;P&gt;filingType      application     recDate     count &lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-03-31  1&lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-04-01      2&lt;/P&gt;

&lt;P&gt;I need to group by oldest recDate so results look like this:&lt;/P&gt;

&lt;P&gt;filingType      application     recDate     count&lt;/P&gt;

&lt;P&gt;MN-CORP-FILING      LACERTE     2013-03-31  3&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 18:38:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82434#M20934</guid>
      <dc:creator>anava</dc:creator>
      <dc:date>2013-04-02T18:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Group by oldest Date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82435#M20935</link>
      <description>&lt;P&gt;I would check the "sort" command. You can append your search with the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort recDate
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps. &lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 19:17:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82435#M20935</guid>
      <dc:creator>tgow</dc:creator>
      <dc:date>2013-04-02T19:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Group by oldest Date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82436#M20936</link>
      <description>&lt;P&gt;That command does not work. In SQL it would read this way:&lt;BR /&gt;
group by filingType, application, min(recDate)&lt;/P&gt;

&lt;P&gt;I need a way of using MIN in splunk&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 19:27:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82436#M20936</guid>
      <dc:creator>anava</dc:creator>
      <dc:date>2013-04-02T19:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Group by oldest Date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82437#M20937</link>
      <description>&lt;P&gt;You can get the minimum of a field using eventstats: &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/eventstats"&gt;http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/eventstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 19:31:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82437#M20937</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-04-02T19:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Group by oldest Date</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82438#M20938</link>
      <description>&lt;P&gt;You should use &lt;CODE&gt;stats&lt;/CODE&gt; in a slightly different manner. The problem is that you are now grouping by a field that will have different values, namely the &lt;CODE&gt;recDate&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Instead you should only group by the first two, and just attach the lowest/earliest value of date for every combination of &lt;CODE&gt;filingType&lt;/CODE&gt; and &lt;CODE&gt;application&lt;/CODE&gt;, along with the count. If your &lt;CODE&gt;recDate&lt;/CODE&gt; is in the format you specify you may need to alter that a bit for sorting purposes.&lt;/P&gt;

&lt;P&gt;Alternative A (this assumes that events you have came in chronologically, which makes the last &lt;EM&gt;retrieved&lt;/EM&gt; event have the earliest &lt;CODE&gt;recDate&lt;/CODE&gt; - remember that a search always returns the newest events first);&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...| stats c last(recDate) as recDate by filingType, application&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Alternative B (which may be just as good, though just a little longer query);&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...| eval rd = strptime(recDate, "%Y-%m-%d") | stats c min(rd) as recDate by filingType, application | eval recDate = strftime(recDate, "%Y-%m-%d")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This converts the date string into &lt;CODE&gt;epoch&lt;/CODE&gt; for each event, which makes it easy to find the &lt;CODE&gt;min()&lt;/CODE&gt; of that. Then it's converted back to a string for presentation purposes.&lt;/P&gt;

&lt;P&gt;EDIT: typos and errors&lt;/P&gt;

&lt;P&gt;Hope this helps, &lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2013 20:14:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Group-by-oldest-Date/m-p/82438#M20938</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-04-02T20:14:21Z</dc:date>
    </item>
  </channel>
</rss>

