<?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 Newbie: Using buckets/bins in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346560#M102640</link>
    <description>&lt;P&gt;hey you can try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;your_index&amp;gt; source=&amp;lt;your_source&amp;gt;
    ...... 
| eval days=round((now()-strptime(OPEN_DATE, "%m%d%Y"))/86400) 
| eval t=days 
| bin days span=29 
| eval days=case(t&amp;gt;=0 AND t&amp;lt;29,"0-29",t&amp;gt;=29 AND t&amp;lt;58,"29-58",t&amp;gt;=58 AND t&amp;lt;87,"58-87",t&amp;gt;=87 AND t&amp;lt;116,"87-116",t&amp;gt;=116 AND t&amp;lt;145,"116-145",t&amp;gt;=145 AND t&amp;lt;174,"145-174",t&amp;gt;=174,"174+") 
| stats count by days 
| sort days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
    <pubDate>Tue, 06 Feb 2018 07:40:02 GMT</pubDate>
    <dc:creator>mayurr98</dc:creator>
    <dc:date>2018-02-06T07:40:02Z</dc:date>
    <item>
      <title>Splunk Newbie: Using buckets/bins</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346558#M102638</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;/P&gt;

&lt;P&gt;I can't seem to find a efficient way to bucket my results where anything greater than 174 days gets tossed to one collective bucket. &lt;BR /&gt;
The table below is the result I want, but what I'm getting are buckets spanning to 10,000 days with each individual count. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[index here] source=[source] 
......
|eval days=round((now()-strptime(OPEN_DATE, "%m%d%Y"))/86400)
|bin days span=29
|stats count  by days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;days    ,         count&lt;BR /&gt;&lt;BR /&gt;
0-29          ,        450&lt;BR /&gt;&lt;BR /&gt;
29-58    ,    411&lt;BR /&gt;&lt;BR /&gt;
58-87   ,    471&lt;BR /&gt;&lt;BR /&gt;
87-116  ,    1389&lt;BR /&gt;&lt;BR /&gt;
116-145,        5828&lt;BR /&gt;&lt;BR /&gt;
145-174 ,    806&lt;BR /&gt;&lt;BR /&gt;
174+    30,,000&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 21:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346558#M102638</guid>
      <dc:creator>rfernandez2010</dc:creator>
      <dc:date>2018-02-05T21:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Newbie: Using buckets/bins</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346559#M102639</link>
      <description>&lt;P&gt;I think you may need to use more of the options for the &lt;CODE&gt;bin&lt;/CODE&gt; command, such as setting the number of bins.&lt;BR /&gt;
You could also calculate this instead of trying to force bin - bin doesn't like unequal bin sizes... but I recommend the case function, which gives you complete control:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval days=round((now()-strptime(OPEN_DATE, "%m%d%Y"))/86400)
| eval day_category=case(days &amp;lt; 30, "0-29",
                  days &amp;lt; 59,"30-58",
                  days &amp;lt; 88,"59-87",
                  days &amp;lt; 117,"88-116",
                  days &amp;lt; 146,"117-145",
                  days &amp;lt; 175,"146-174",
                  true(),"174+")
| stats count by date_category
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note a couple of things about the case function: it takes the value corresponding to the first match. So if days is 118, then the day_category will be assigned to "117-145". The &lt;CODE&gt;true()&lt;/CODE&gt; in the last part of the case function defines a default value, which will be used if no other test matches. &lt;/P&gt;

&lt;P&gt;The formatting is just to make it easy to read; you can put the whole case function on a single line; Splunk doesn't care.&lt;/P&gt;

&lt;P&gt;Finally, the categories that you defined in your desired output are overlapping. I corrected that in my case statement.&lt;/P&gt;

&lt;P&gt;HTH!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 01:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346559#M102639</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2018-02-06T01:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Newbie: Using buckets/bins</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346560#M102640</link>
      <description>&lt;P&gt;hey you can try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;your_index&amp;gt; source=&amp;lt;your_source&amp;gt;
    ...... 
| eval days=round((now()-strptime(OPEN_DATE, "%m%d%Y"))/86400) 
| eval t=days 
| bin days span=29 
| eval days=case(t&amp;gt;=0 AND t&amp;lt;29,"0-29",t&amp;gt;=29 AND t&amp;lt;58,"29-58",t&amp;gt;=58 AND t&amp;lt;87,"58-87",t&amp;gt;=87 AND t&amp;lt;116,"87-116",t&amp;gt;=116 AND t&amp;lt;145,"116-145",t&amp;gt;=145 AND t&amp;lt;174,"145-174",t&amp;gt;=174,"174+") 
| stats count by days 
| sort days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 07:40:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346560#M102640</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-02-06T07:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Newbie: Using buckets/bins</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346561#M102641</link>
      <description>&lt;P&gt;Awesome, worked like a charm. &lt;/P&gt;

&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 13:48:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Newbie-Using-buckets-bins/m-p/346561#M102641</guid>
      <dc:creator>rfernandez2010</dc:creator>
      <dc:date>2018-02-06T13:48:43Z</dc:date>
    </item>
  </channel>
</rss>

