<?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: Splunk conditional count/aggregation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363927#M107439</link>
    <description>&lt;P&gt;Exactly what I was looking for, thanks for your help.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Mar 2018 16:57:43 GMT</pubDate>
    <dc:creator>bomran</dc:creator>
    <dc:date>2018-03-19T16:57:43Z</dc:date>
    <item>
      <title>Splunk conditional count/aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363925#M107437</link>
      <description>&lt;P&gt;I have some CSV data about files imported in to Splunk. The data looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"\\domain\path\to\file\","&amp;lt;filename&amp;gt;","&amp;lt;fsize&amp;gt;","&amp;lt;ext&amp;gt;","&amp;lt;Last_access&amp;gt;","&amp;lt;last_write&amp;gt;","&amp;lt;creation_time&amp;gt;","&amp;lt;attributes&amp;gt;","&amp;lt;owner&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have converted all the date strings to epoch using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval epoch_LastAccessTime=strptime(LastAccessTime, "%d/%m/%Y %H:%M:%S")
...
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to get:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;A percentage of files last accessed between 6 months and 3 years ago&lt;/LI&gt;
&lt;LI&gt;A percentage of files last accessed 3 years or more ago.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This is the search query that I have tried before getting stuck:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="&amp;lt;my_index&amp;gt;" sourcetype="&amp;lt;my_sourcetype&amp;gt;" 
| rex field=DirectoryName "\\\domain\.org\\\teams\\\(?&amp;lt;Team&amp;gt;[^\\\]*)" 
offset_field=_extracted_fields_bounds  
| eval epoch_LastAccessTime=strptime(LastAccessTime, "%d/%m/%Y 
%H:%M:%S") 
| eval _time=epoch_LastAccessTime
| timechart span=6mon count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've tried using commands along the lines of:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where epoch_LastAccessTime&amp;gt;=three_year_ago_from_now AND 
epoch_LastAccessTime&amp;lt;=six_months_ago_from_now
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, this excludes everything else (3y+)&lt;/P&gt;

&lt;P&gt;I want the result to look something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TimeRange  Perc
6m-3y      60%
3y+        40%
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Mar 2018 15:55:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363925#M107437</guid>
      <dc:creator>bomran</dc:creator>
      <dc:date>2018-03-19T15:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk conditional count/aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363926#M107438</link>
      <description>&lt;P&gt;Your nearly on the right track.  Instead of using a &lt;CODE&gt;where&lt;/CODE&gt; to limit your results, use an &lt;CODE&gt;eval&lt;/CODE&gt; to build a new categorical field.  At that point you'll no longer need the timechart.&lt;/P&gt;

&lt;P&gt;Something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval TimeRange=case(epoch_LastAccessTime&amp;gt;=three_year_ago_from_now, "3y+",
                      epoch_LastAccessTime&amp;gt;=six_months_ago_from_now, "6m-3y",
                      0=0, "less than 6m")
| stats count by TimeRange
| eventstats sum(count) as total_count
| eval pct=100*count/total_count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note "0=0" is used to provide a "default" option, since it's always true.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:07:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363926#M107438</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2018-03-19T16:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk conditional count/aggregation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363927#M107439</link>
      <description>&lt;P&gt;Exactly what I was looking for, thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-conditional-count-aggregation/m-p/363927#M107439</guid>
      <dc:creator>bomran</dc:creator>
      <dc:date>2018-03-19T16:57:43Z</dc:date>
    </item>
  </channel>
</rss>

