<?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: How do you aggregate logic based on dates? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390384#M113703</link>
    <description>&lt;P&gt;Did this work for you, @joydeep741?&lt;/P&gt;</description>
    <pubDate>Tue, 12 Feb 2019 00:03:59 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-02-12T00:03:59Z</dc:date>
    <item>
      <title>How do you aggregate logic based on dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390380#M113699</link>
      <description>&lt;P&gt;I have a query which gives a "per day count of a particular field" in the last 60 days.&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
&lt;STRONG&gt;TIME             COUNT&lt;/STRONG&gt;&lt;BR /&gt;
01-11-2018      43&lt;BR /&gt;
01-11-2018      66&lt;BR /&gt;
01-11-2018      87&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
30-12-2018      76&lt;BR /&gt;
31-12-2018      66&lt;/P&gt;

&lt;P&gt;Now, I wish to SUM these counts in the following way:&lt;BR /&gt;
- SUM of first 10 days&lt;BR /&gt;
- SUM of first month&lt;BR /&gt;
- SUM of second month&lt;/P&gt;

&lt;P&gt;Can I do that in a single query ?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 06:03:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390380#M113699</guid>
      <dc:creator>joydeep741</dc:creator>
      <dc:date>2018-12-31T06:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you aggregate logic based on dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390381#M113700</link>
      <description>&lt;P&gt;Events typically have a field extracted from timestamps that represents the month of the timestamp. If your above data doesn't have this then you'll need to use a rex or eval to get it. Then, in order to get the "first ten days" I'd suggest adding a fake zeroth month to that field for those days. Then getting your sums is a matter of splitting a stats sum by month.&lt;/P&gt;

&lt;P&gt;Assuming you have the month and day fields, try something like the following:&lt;BR /&gt;
    | eval month=if(month == 11 AND day &amp;lt; 11, mvappend(month-1), month)&lt;BR /&gt;
    | stats sum(count) by month&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 06:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390381#M113700</guid>
      <dc:creator>badarsebard</dc:creator>
      <dc:date>2018-12-31T06:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you aggregate logic based on dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390382#M113701</link>
      <description>&lt;P&gt;@joydeep741,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"your current search to get the count"|eval mon=strftime(strptime(TIME,"%d-%m-%Y"),"%m")|streamstats count as sno|streamstats count as month by mon
|streamstats count(eval(if(month==1,1,null()))) as month
|eventstats sum(eval(if(sno&amp;lt;11,count,null()))) as first10,sum(eval(if(month==1,count,null()))) as firstMonth,
            sum(eval(if(month==2,count,null()))) as secondMonth  |fields - mon,month,sno
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please note that , here first 10, first month, second month etc are based on the order of your events. This should work for any time range/duration you select&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2018 07:28:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390382#M113701</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-12-31T07:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do you aggregate logic based on dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390383#M113702</link>
      <description>&lt;P&gt;Add something like this to the end of your existing search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval thisMonthStart=relative_time(now(), "@mon")
| eval lastMonthStart=relative_time(now(), "-1mon@mon")
| eval first10days = if(((_time &amp;gt;= thisMonthStart) AND (_time &amp;lt;= relative_time(thisMonthStart, "+10d"))), 1, 0)
| eval thisMonth = if((_time &amp;gt;= lastMonthStart), 1, 0)
| eval lastMonth = if(((_time &amp;gt;= lastMonthStart) AND (_time &amp;lt;= thisMonthStart)), 1, 0)
| multireport
[ | where first10days==1 | stats sum(COUNT) AS first10days ]
[ | where thisMonth==1 | stats sum(COUNT) AS thisMonth ]
[ | where lastMonth==1 | stats sum(COUNT) AS lastMonth ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Feb 2019 01:19:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390383#M113702</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-03T01:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do you aggregate logic based on dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390384#M113703</link>
      <description>&lt;P&gt;Did this work for you, @joydeep741?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 00:03:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-aggregate-logic-based-on-dates/m-p/390384#M113703</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-12T00:03:59Z</dc:date>
    </item>
  </channel>
</rss>

