<?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: Stats count and field with oldest event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528217#M149142</link>
    <description>&lt;P&gt;Just a quick comment on first(), earliest() and earliest_time()&lt;/P&gt;&lt;P&gt;first() is about event order and not related to time. earliest(X) will find the earliest _value_ of X and earliest_time(X) finds the earliest _time of X according to the event's _time field&lt;/P&gt;&lt;P&gt;See&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.0/SearchReference/Stats#Usage" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.0/SearchReference/Stats#Usage&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Nov 2020 20:51:45 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2020-11-05T20:51:45Z</dc:date>
    <item>
      <title>Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528207#M149134</link>
      <description>&lt;P&gt;I'm sure it's out there somewhere and maybe I'm just brain fried from looking at Splunk for too long, but I wasn't able to find or figure it out. Any help linking me to the answer or providing the answer would be greatly appreciated. I'm generating the results shown in the screen capture with this search&amp;nbsp;-&amp;nbsp;index="&amp;lt;my index&amp;gt;" sourcetype="&amp;lt;my sourcetype&amp;gt;"&lt;BR /&gt;| stats count BY Plugin,Severity&lt;BR /&gt;| sort -count&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dangeloma_0-1604606188320.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/11665iAEA36BA473D60173/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dangeloma_0-1604606188320.png" alt="dangeloma_0-1604606188320.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'd like to add a column called "First Discovered" which contains a date value and I only want to see the oldest date from that field data. If I add to the stats count command "First Discovered" it's not going to work because there are multiple unique values. What's the best way to return the data I already have but add a column containing the oldest date from the field "First Discovered", for each of the Plugins. "First Discovered" data sample is -&amp;nbsp;&lt;SPAN&gt;Jul 2, 2020 02:23:25 EDT and in case I wasn't clear, this field is extracted from the logs along with the "Plugin" and "Severity" fields.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 20:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528207#M149134</guid>
      <dc:creator>dangeloma</dc:creator>
      <dc:date>2020-11-05T20:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528209#M149136</link>
      <description>&lt;P&gt;This is what I have used and it seems to work well.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;| stats count first(_time) as LastSeen by plugin, severity&amp;nbsp;&lt;BR /&gt;| eval lastSeen=strftime(lastSeen, "%m/%d/%d %H:%M:%S")&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 20:14:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528209#M149136</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2020-11-05T20:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528211#M149137</link>
      <description>&lt;P&gt;Thank you, that gets me a lot closer. I can't use "_time" because I'm ingesting the data from a CSV. So all of the events are stamped with the same ingestion time. I did modify your search to use the "First Discovered" field.&lt;/P&gt;&lt;P&gt;| stats count first("First Discovered") as "First Discovered" by Plugin, Severity&lt;/P&gt;&lt;P&gt;It returned "&lt;SPAN&gt;Jul 2, 2020 02:23:25 EDT" but the oldest value I have for the sample plugin I searched is "Sep 9, 2019 18:13:38 EDT".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I also tried "| stats count earliest" and the same date was returned. If I run the search with "| sort 1 -"First Discovered" and leave out the stats functions I get the date from 2019.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 20:36:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528211#M149137</guid>
      <dc:creator>dangeloma</dc:creator>
      <dc:date>2020-11-05T20:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528216#M149141</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/224059"&gt;@dangeloma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You just need to parse the date value before doing stats and then you use min(), i.e.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval fdd=strptime('First Discovered', "%b %d, %Y %H:%M:%S %Z")
| stats count min(fdd) as fdd BY Plugin,Severity
| sort -count
| eval "First Discovered"=strftime(fdd, "%b %d, %Y %H:%M:%S")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;So, you're just converting your first discovered date to an epoch, then min() is just looking for the lowest, i.e. oldest, date. Then you just reformat the date as needed after the stats.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 20:46:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528216#M149141</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-11-05T20:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528217#M149142</link>
      <description>&lt;P&gt;Just a quick comment on first(), earliest() and earliest_time()&lt;/P&gt;&lt;P&gt;first() is about event order and not related to time. earliest(X) will find the earliest _value_ of X and earliest_time(X) finds the earliest _time of X according to the event's _time field&lt;/P&gt;&lt;P&gt;See&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.0/SearchReference/Stats#Usage" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/8.1.0/SearchReference/Stats#Usage&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 20:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528217#M149142</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-11-05T20:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count and field with oldest event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528315#M149166</link>
      <description>&lt;P&gt;Thank you, this also got me a lot closer. I ended up having to convert the time with "mktime".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename "First Discovered" AS FD 
| convert timeformat="%b %d, %Y %H:%M:%S %Z" mktime(FD) 
| stats count min("FD") AS FD BY Plugin,Severity
| fieldformat FD=strftime(FD,"%m-%d-%Y %H:%M:%S %Z") 
| sort -count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This post helped with the conversion:&lt;BR /&gt;&lt;A title="How can i convert String Type Time field(a) to a human readable Date Type Time field" href="https://community.splunk.com/t5/Splunk-Search/How-can-i-convert-String-Type-Time-field-a-to-a-human-readable/m-p/93941#M24184" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/How-can-i-convert-String-Type-Time-field-a-to-a-human-readable/m-p/93941#M24184&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 13:10:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-and-field-with-oldest-event/m-p/528315#M149166</guid>
      <dc:creator>dangeloma</dc:creator>
      <dc:date>2020-11-06T13:10:15Z</dc:date>
    </item>
  </channel>
</rss>

