<?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: timechart shows 0 when there is no result in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155064#M43619</link>
    <description>&lt;P&gt;I have two thoughts on this, the first being to save processing time by doing everything you have so far in one search like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="perform" ("Bytes Received/sec" OR  sourcetype="Perfmon:Processor118") | timechart span=1h count(eval(searchmatch("Bytes Received/sec"))) as num1 count(eval(sourcetype="Perfmon:Processor118")) as num2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next we generate a dummy event for each hour that won't match either condition but with events we ensure the timechart runs and spits out zeroes if appropriate. (not sure if this is necessary but that looks like):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="perform" ("Bytes Received/sec" OR  sourcetype="Perfmon:Processor118") | append [gentimes [noop | stats count | addinfo | convert timeformat="%m/%d/%Y:%T" ctime(info_*_time) | rename info_min_time as start info_max_time as end | fields start end | format "" "" "" "" "" ""] increment=1h | rename starttime as _time | fields] | timechart span=1h count(eval(searchmatch("Bytes Received/sec"))) as num1 count(eval(sourcetype="Perfmon:Processor118")) as num2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Check out the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/gentimes"&gt;gentimes&lt;/A&gt; and  &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/append"&gt;append&lt;/A&gt; commands for generating dummy events. The subsearch inside the append subsearch is just to figure out the start and end parameter for gentimes based on the selected timeframe. &lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2015 06:09:46 GMT</pubDate>
    <dc:creator>acharlieh</dc:creator>
    <dc:date>2015-08-05T06:09:46Z</dc:date>
    <item>
      <title>timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155061#M43616</link>
      <description>&lt;P&gt;Hi guys, I have a problem with timechart and I need ur help!&lt;BR /&gt;
I got a search line here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="perform" "Bytes Received/sec" | timechart span=1h count as num1 | fillnull
| join [search index="perform" sourcetype="Perfmon:Processor118"| timechart span=1h count as num2 | fillnull] 
| table _time num1 num2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When both subqueries get results, it works well and some empty slots are filled with 0. However, these subqueries usually get only a few results or maybe no results at all ( which means the machine works well ). In this case, I get "no result" in my dashboard when either subquery returns nothing. Fillnull doesn't help. &lt;BR /&gt;
I want to get:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                num1  num2
2015-07-31 09:00:00 4    0
2015-07-31 10:00:00 10    0
2015-07-31 11:00:00 11  0
2015-07-31 12:00:00 12  0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; _time               num1  num2
    2015-07-31 09:00:00 0   4
    2015-07-31 10:00:00 0    4
    2015-07-31 11:00:00 0   4
    2015-07-31 12:00:00 0   4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or even&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; _time               num1  num2
    2015-07-31 09:00:00 0   0
    2015-07-31 10:00:00 0    0
    2015-07-31 11:00:00 0   0
    2015-07-31 12:00:00 0   0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in my dashboard. How can I do that? Thx a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 03:30:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155061#M43616</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-05T03:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155062#M43617</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="perform" "Bytes Received/sec" | timechart span=1h count as num1 
 | join [search index="perform" sourcetype="Perfmon:Processor118"| timechart span=1h count as num2 ] \
 | appendpipe [| gentimes start=-1 | addinfo | eval temp=info_min_time." ".info_max_time | makemv temp | mvexpand temp | rename temp as _time | table _time ]
 | table _time num1 num2 | fillnull | timechart span=1h sum(*) as *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Aug 2015 03:46:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155062#M43617</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-05T03:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155063#M43618</link>
      <description>&lt;P&gt;Doesn't work...when either subquery returns nothing, the table shows like:&lt;BR /&gt;
_time                       num1      num2&lt;BR /&gt;
1970-01-01 08:00    0         0&lt;BR /&gt;
and there's only one row.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 04:27:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155063#M43618</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-05T04:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155064#M43619</link>
      <description>&lt;P&gt;I have two thoughts on this, the first being to save processing time by doing everything you have so far in one search like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="perform" ("Bytes Received/sec" OR  sourcetype="Perfmon:Processor118") | timechart span=1h count(eval(searchmatch("Bytes Received/sec"))) as num1 count(eval(sourcetype="Perfmon:Processor118")) as num2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next we generate a dummy event for each hour that won't match either condition but with events we ensure the timechart runs and spits out zeroes if appropriate. (not sure if this is necessary but that looks like):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="perform" ("Bytes Received/sec" OR  sourcetype="Perfmon:Processor118") | append [gentimes [noop | stats count | addinfo | convert timeformat="%m/%d/%Y:%T" ctime(info_*_time) | rename info_min_time as start info_max_time as end | fields start end | format "" "" "" "" "" ""] increment=1h | rename starttime as _time | fields] | timechart span=1h count(eval(searchmatch("Bytes Received/sec"))) as num1 count(eval(sourcetype="Perfmon:Processor118")) as num2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Check out the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/gentimes"&gt;gentimes&lt;/A&gt; and  &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/append"&gt;append&lt;/A&gt; commands for generating dummy events. The subsearch inside the append subsearch is just to figure out the start and end parameter for gentimes based on the selected timeframe. &lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 06:09:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155064#M43619</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-08-05T06:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155065#M43620</link>
      <description>&lt;P&gt;In fact, sometime I face the same issue when I use the subqueries with different indexes. If so can I use your way? If yes, how?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 06:35:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155065#M43620</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-05T06:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155066#M43621</link>
      <description>&lt;P&gt;need help...&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 09:51:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155066#M43621</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-05T09:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155067#M43622</link>
      <description>&lt;P&gt;Assuming the other queries follow the same pattern separate indexes don't matter. The search is all of them OR'ed together (or you use multisearch) then you adjust the count conditions accordingly. (The part inside eval is just like a where statement)&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 11:20:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155067#M43622</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-08-05T11:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155068#M43623</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="perform" "Bytes Received/sec"  append [search earliest =-1h@h index=* OR index=_* | head 1] | timechart span=1h count as num1 | fillnull | join [search index="perform" sourcetype="Perfmon:Processor118" append [search earliest =-1h@h index=* OR index=_* | head 1] | timechart span=1h count as num2 | fillnull] | table _time num1 num2  | eval tooMany=strftime(now(), "%Y-%m-%d %H") . ":00" | eval tooMany = round(strptime(tooMany, "%Y-%m-%d %H")) | eval num1 = num1 - if(_time=tooMany, 1, 0) | eval num2 = num2 - if(_time=tooMany, 1, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This makes sure the last row always has 1 extra (never all zeros) and then subtracts it at the end.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 13:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155068#M43623</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-05T13:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155069#M43624</link>
      <description>&lt;P&gt;Is your time range selected for search "All time"? &lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2015 14:44:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155069#M43624</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-05T14:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155070#M43625</link>
      <description>&lt;P&gt;I did choose "All time" so I tried "Last 24 hours" later. Well it shows the data of every hour by now but when one of the subquery returns nothing ( let's say column "num1" shows all 0 ), no matter if column "num2" should return something or not, column "num2" shows all 0, too.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 01:18:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155070#M43625</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-06T01:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155071#M43626</link>
      <description>&lt;P&gt;Works! Thank you! &lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 01:52:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155071#M43626</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-06T01:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155072#M43627</link>
      <description>&lt;P&gt;I am sure you noticed that the last &lt;CODE&gt;eval&lt;/CODE&gt; was wrong (had &lt;CODE&gt;num1&lt;/CODE&gt; instead of &lt;CODE&gt;num2&lt;/CODE&gt;).  I fixed my answer (but you must have done so already if it worked for you) so nobody else will be confused.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 02:35:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155072#M43627</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-06T02:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: timechart shows 0 when there is no result</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155073#M43628</link>
      <description>&lt;P&gt;In fact I just edited my comment a few minutes before your comment, and I asked why num2 didn't need to be subtracted ( silly me ). Anyway thx again!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2015 03:41:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-shows-0-when-there-is-no-result/m-p/155073#M43628</guid>
      <dc:creator>LuiesCui</dc:creator>
      <dc:date>2015-08-06T03:41:55Z</dc:date>
    </item>
  </channel>
</rss>

