<?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 Using multiple time range on the same index to return different row values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495363#M138107</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I have a report that searches for differents time range like Year to now, Month to now, Last 5 days and last 24 hrs.&lt;/P&gt;

&lt;P&gt;The current search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Last 24 hrs"
| append [ search "same search index" earliest=-5d@d latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Last 5 days"]
| append [ search "same search index" earliest=-0mon@mon latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Month to now"]
| append [ search "same search index" earliest=-0year@year latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total", earliest(_time) as "Date"
| convert timeformat="%m/%d/%Y" ctime("Date") as "Date"
| eval "Date" = "Year to now - ".'Date']
| table "Date", "Failures", "Passed", "Total"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The final result is a table with 4 rows in it. Containing Last 24 hours, Last 5 days, Month to now and Year to now results.&lt;/P&gt;

&lt;P&gt;So the problem that I'm currently facing is sometimes the Year to now results, returns a different Date like 01/27/2020. It's supposed to be the first day of the current year.&lt;/P&gt;

&lt;P&gt;The Job Inspect tells me that the append command is consuming a lot of time to be completed.&lt;/P&gt;

&lt;P&gt;Is it possible to do the longest search (Year to now) and have multiples stats commands by different time range to get the final result or a way to improve this search?&lt;/P&gt;

&lt;P&gt;Thanks for all your help.&lt;/P&gt;</description>
    <pubDate>Fri, 08 May 2020 12:06:29 GMT</pubDate>
    <dc:creator>egonstep</dc:creator>
    <dc:date>2020-05-08T12:06:29Z</dc:date>
    <item>
      <title>Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495363#M138107</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I have a report that searches for differents time range like Year to now, Month to now, Last 5 days and last 24 hrs.&lt;/P&gt;

&lt;P&gt;The current search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search index
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Last 24 hrs"
| append [ search "same search index" earliest=-5d@d latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Last 5 days"]
| append [ search "same search index" earliest=-0mon@mon latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total"
| eval "Date" = "Month to now"]
| append [ search "same search index" earliest=-0year@year latest=now()
| stats sum(FAIL) as "Failures", sum(PASS) as "Passed", sum(TOTAL) as "Total", earliest(_time) as "Date"
| convert timeformat="%m/%d/%Y" ctime("Date") as "Date"
| eval "Date" = "Year to now - ".'Date']
| table "Date", "Failures", "Passed", "Total"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The final result is a table with 4 rows in it. Containing Last 24 hours, Last 5 days, Month to now and Year to now results.&lt;/P&gt;

&lt;P&gt;So the problem that I'm currently facing is sometimes the Year to now results, returns a different Date like 01/27/2020. It's supposed to be the first day of the current year.&lt;/P&gt;

&lt;P&gt;The Job Inspect tells me that the append command is consuming a lot of time to be completed.&lt;/P&gt;

&lt;P&gt;Is it possible to do the longest search (Year to now) and have multiples stats commands by different time range to get the final result or a way to improve this search?&lt;/P&gt;

&lt;P&gt;Thanks for all your help.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 12:06:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495363#M138107</guid>
      <dc:creator>egonstep</dc:creator>
      <dc:date>2020-05-08T12:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495364#M138108</link>
      <description>&lt;P&gt;Hi @egonstep,&lt;/P&gt;

&lt;P&gt;I created this hack earlier which might be helpful here. So It gives you behavior where you have multiple searches as your basesearch and then you combine all those search results into one search. Which is as follows:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Define your searches as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;index="X" | stats count  | eval "search name"="search1"&amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-24h&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="search1_sid"&amp;gt;$job.sid$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;index="Y" | stats count | eval "search name"="search2"&amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-7d&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="search2_sid"&amp;gt;$job.sid$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Step 2&lt;/STRONG&gt;: Now the &lt;CODE&gt;sid&lt;/CODE&gt;s will set when the searches are finished execution. Use them in the main search with &lt;CODE&gt;loadjob&lt;/CODE&gt; command as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| loadjob $search1_sid$
| append 
    [| loadjob $search2_sid$ ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As the searches ran parallel (having separate job for each search) and the results in the main search are fetched directly from the job &lt;CODE&gt;sid&lt;/CODE&gt;, this way you can combine results of long-running searches without affecting them by &lt;CODE&gt;append&lt;/CODE&gt; as before.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;: You can also split the search across multiple report searches.&lt;/P&gt;

&lt;P&gt;Hope this was helpful.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Harsh&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 13:43:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495364#M138108</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-05-08T13:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495365#M138109</link>
      <description>&lt;P&gt;Hey harshpatel, thanks for your answer.&lt;/P&gt;

&lt;P&gt;But I have a question, this is to create a new dashboard to be sent as pdf, right?&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 11:59:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495365#M138109</guid>
      <dc:creator>egonstep</dc:creator>
      <dc:date>2020-05-12T11:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495366#M138110</link>
      <description>&lt;P&gt;@egonstep, Yes it requires creating a dashboard. Also I've added an edit saying you can create multiple savedsearch as well like this. You can specify savedsearch name to &lt;CODE&gt;loadjob&lt;/CODE&gt; command as well in your report search. For documentation (&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.3/SearchReference/Loadjob"&gt;https://docs.splunk.com/Documentation/Splunk/8.0.3/SearchReference/Loadjob&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 16:40:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495366#M138110</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-05-12T16:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495367#M138111</link>
      <description>&lt;P&gt;@harshpatel I see, thanks for the help, I'll try to create this way to see if everything works just fine.&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 20:07:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/495367#M138111</guid>
      <dc:creator>egonstep</dc:creator>
      <dc:date>2020-05-12T20:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple time range on the same index to return different row values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/611544#M212622</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/156506"&gt;@harshpatel&lt;/a&gt;&amp;nbsp;could you provide the full dashboard code example? I was not able to successfully use this approach&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 06:43:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-multiple-time-range-on-the-same-index-to-return-different/m-p/611544#M212622</guid>
      <dc:creator>BenTreeser</dc:creator>
      <dc:date>2022-09-01T06:43:08Z</dc:date>
    </item>
  </channel>
</rss>

