<?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: Comparing today's data with last week's data in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53262#M12948</link>
    <description>&lt;P&gt;There are solutions! If you are willing decide up-front that you want the timechart to report in 30-minute intervals (or longer), try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-0d@d latest=now |
bucket _time span=30m |
stats avg(Time) as avgTme by _time |
eval ReportKey="Today" | 
append [search sourcetype="abc" Service="xyz" earliest=-7d@d latest=-6d@d | 
bucket _time span=30m |
stats avg(Time) as avgTme by _time |
eval ReportKey="LastWeek" | 
eval _time=_time+(60*60*24*7)] | 
chart max(avgTme) as avgTime over _time by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above summarizes the data before returning from the subsearch. And another way of doing it, which may be even better:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-7d@d latest=now |
fields Time |
eval weekAgo = relative_time(now(), "-6d@d") |
eval today = relative_time(now(), "@d") |
eval ReportKey = "omit" |
eval ReportKey = case(_time &amp;lt; weekAgo,"Last Week", _time &amp;gt; today,"Today") |
where ReportKey != "omit" |
eval _time = if(ReportKey=="Last Week", _time+(60*60*24*7), _time) |
timechart fixedrange=f avg(Time) as avgTime by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This second solution does not use a subsearch. Instead, it collects all the data for the last week, and then categorizes it based on _time. If the data is not during the time that we want, it is dropped by the where command. The _time is tweaked for data from a week ago, and then reported by the categories.&lt;/P&gt;

&lt;P&gt;I haven't actually tested these searches, so there may be typos. (I try to check...) Let me know if it doesn't work, and I'll help debug my typing!&lt;/P&gt;</description>
    <pubDate>Thu, 17 May 2012 01:08:57 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2012-05-17T01:08:57Z</dc:date>
    <item>
      <title>Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53258#M12944</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a problem with comparing today's data with data from a week ago.  Here is the query I run: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-0d@d latest=now | eval ReportKey="Today" | append [search sourcetype="abc" Service="xyz" earliest=-7d@d latest=-6d@d | eval ReportKey="LastWeek" | eval new_time=_time+60*60*24*7] | eval _time=if(isnotnull(new_time), new_time, _time) | timechart avg(Time) by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works to some extend.  The issue is that the subquery - data from a week ago - does not appear fully.  Meaning I can see data from 4PM until midnight but not prior to 4PM and I know for a fact that there is data for the entire day - starting at 00:00:01AM.&lt;/P&gt;

&lt;P&gt;Can someone help me with this one?&lt;/P&gt;

&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2012 13:58:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53258#M12944</guid>
      <dc:creator>fpigeon</dc:creator>
      <dc:date>2012-05-16T13:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53259#M12945</link>
      <description>&lt;P&gt;I see a possible problem in your search, but I don't think that it is causing the incomplete subsearch results. I would do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-0d@d latest=now |
eval ReportKey="Today" | 
append [search sourcetype="abc" Service="xyz" earliest=-7d@d latest=-6d@d | 
eval ReportKey="LastWeek" | 
eval _time=_time+60*60*24*7] | 
timechart avg(Time) by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How many events &lt;STRONG&gt;should&lt;/STRONG&gt; be returned from your subsearch? What did you get when you ran  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc"  Service="xyz" earliest=-7d@d latest=-6d@d | 
eval ReportKey="LastWeek" | 
eval _time=_time+60*60*24*7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The maximum number of events that can be returned from a subsearch is 10500, but it might be set lower in your Splunk environment.&lt;/P&gt;

&lt;P&gt;There is more info in the Splunk User Manual under &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/User/HowSubsearchesWork"&gt;Performance of Subsearches&lt;/A&gt; (in the middle of the page)&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2012 18:02:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53259#M12945</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-16T18:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53260#M12946</link>
      <description>&lt;P&gt;You might have a slight typo in the search - &lt;CODE&gt;avg(Time)&lt;/CODE&gt;, however &lt;CODE&gt;Time&lt;/CODE&gt; is never evaluated.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2012 19:18:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53260#M12946</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-05-16T19:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53261#M12947</link>
      <description>&lt;P&gt;You are right, the subsearch returns 123,949 matching events which is way over the 10,500 you mentioned in your post.  I guess now I will have to find a better way to compare today's values with last week's values.&lt;/P&gt;

&lt;P&gt;Thank you very much for your precious time.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 00:10:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53261#M12947</guid>
      <dc:creator>fpigeon</dc:creator>
      <dc:date>2012-05-17T00:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53262#M12948</link>
      <description>&lt;P&gt;There are solutions! If you are willing decide up-front that you want the timechart to report in 30-minute intervals (or longer), try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-0d@d latest=now |
bucket _time span=30m |
stats avg(Time) as avgTme by _time |
eval ReportKey="Today" | 
append [search sourcetype="abc" Service="xyz" earliest=-7d@d latest=-6d@d | 
bucket _time span=30m |
stats avg(Time) as avgTme by _time |
eval ReportKey="LastWeek" | 
eval _time=_time+(60*60*24*7)] | 
chart max(avgTme) as avgTime over _time by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above summarizes the data before returning from the subsearch. And another way of doing it, which may be even better:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="abc" Service="xyz" earliest=-7d@d latest=now |
fields Time |
eval weekAgo = relative_time(now(), "-6d@d") |
eval today = relative_time(now(), "@d") |
eval ReportKey = "omit" |
eval ReportKey = case(_time &amp;lt; weekAgo,"Last Week", _time &amp;gt; today,"Today") |
where ReportKey != "omit" |
eval _time = if(ReportKey=="Last Week", _time+(60*60*24*7), _time) |
timechart fixedrange=f avg(Time) as avgTime by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This second solution does not use a subsearch. Instead, it collects all the data for the last week, and then categorizes it based on _time. If the data is not during the time that we want, it is dropped by the where command. The _time is tweaked for data from a week ago, and then reported by the categories.&lt;/P&gt;

&lt;P&gt;I haven't actually tested these searches, so there may be typos. (I try to check...) Let me know if it doesn't work, and I'll help debug my typing!&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 01:08:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53262#M12948</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-17T01:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53263#M12949</link>
      <description>&lt;P&gt;Wow!  It is actually working, thank you so much.  Now, if I may push my luck even more &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  I was wondering if there is a way to improve the readability of the chart.  When I look at the chart I see seven days even if the data is plotted on a single day.  Therefore, I was wondering if it would be possible to remove the other days from the chart so it shows only today.&lt;/P&gt;

&lt;P&gt;Thank you again.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 02:29:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53263#M12949</guid>
      <dc:creator>fpigeon</dc:creator>
      <dc:date>2012-05-17T02:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53264#M12950</link>
      <description>&lt;P&gt;Okay, I just noticed a typo and fixed it. Which one of the searches are you using? I am not sure why the spread is still 7 days, but knowing which version you are using will give me a start.&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 05:13:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53264#M12950</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-17T05:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53265#M12951</link>
      <description>&lt;P&gt;Hi, I tried both but the spread appears only on the second search.  My basic understanding why I see the spread is because in the search I specify earliest=-7d@d latest=now even though the data returned is showed under one single day.  What do you think?&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 16:07:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53265#M12951</guid>
      <dc:creator>fpigeon</dc:creator>
      <dc:date>2012-05-17T16:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53266#M12952</link>
      <description>&lt;P&gt;I am trying to accomplish basically the same thing, but I cannot get it to work.  I want a line chart with two lines.  One showing a count of events for the past 24 hours, and another line showing a count of the past 24 hours from a week ago (same time period)&lt;/P&gt;

&lt;P&gt;I want to base the search only on a source type and not a field.  I just want to be able to have a visual representation of the total alerts from the two different time periods.&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2012 12:28:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53266#M12952</guid>
      <dc:creator>mcbradford</dc:creator>
      <dc:date>2012-05-18T12:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53267#M12953</link>
      <description>&lt;P&gt;I think you may be right - what happens if you add fixedrange to the timechart command as&lt;/P&gt;

&lt;P&gt;timechart fixedrange=f avg(Time) as avgTime by ReportKey&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2012 06:39:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53267#M12953</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-19T06:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing today's data with last week's data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53268#M12954</link>
      <description>&lt;P&gt;Okay, try this&lt;/P&gt;

&lt;P&gt;sourcetype=yoursourcetype |&lt;BR /&gt;
eval weekAgo = relative_time(now(), "-6d\@d") |&lt;BR /&gt;
eval today = relative_time(now(), "\@d") |&lt;BR /&gt;
eval ReportKey = "omit" |&lt;BR /&gt;
eval ReportKey = case(_time &amp;lt; weekAgo,"Last Week", _time &amp;gt; today,"Today") |&lt;BR /&gt;
where ReportKey != "omit" |&lt;BR /&gt;
eval _time = if(ReportKey=="Last Week", _time+(60*60*24*7), _time) |&lt;BR /&gt;
timechart fixedrange=f count by ReportKey&lt;/P&gt;

&lt;P&gt;If that doesn't work for you, you should probably open another Question on the forum and include some additional details!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:50:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-today-s-data-with-last-week-s-data/m-p/53268#M12954</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2020-09-28T11:50:46Z</dc:date>
    </item>
  </channel>
</rss>

