<?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 to add missing values to stats command result? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397031#M115262</link>
    <description>&lt;P&gt;As mentioned ,you could convert _time to the CREATED_DATE as &lt;CODE&gt;CREATED_DATE=strftime(_time,"%Y-%m-%d")&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 20:53:16 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2020-09-29T20:53:16Z</dc:date>
    <item>
      <title>How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397026#M115257</link>
      <description>&lt;P&gt;I have a search query &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xyz | stats count by created_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get results like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;CREATED_DATE          COUNT
2018-08-08                  12
2018-08-07                   10
2018-08-04                   05
2018-08-02                  06
2018-08-01                   03
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But as you can see, some dates are not present in logs so do not appear in results.&lt;BR /&gt;
Like 2018-08-06,  2018-08-05,  2018-08-03&lt;/P&gt;

&lt;P&gt;I want these dates to come but with ZERO count.&lt;/P&gt;

&lt;P&gt;The final result should look like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;CREATED_DATE          COUNT
2018-08-08                  12
2018-08-07                   10
**2018-08-06                   0
2018-08-05                   0**
2018-08-04                   05
**2018-08-03                   0**
2018-08-02                  06
2018-08-01                   03
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please suggest a solution.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 05:13:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397026#M115257</guid>
      <dc:creator>joydeep741</dc:creator>
      <dc:date>2018-08-09T05:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397027#M115258</link>
      <description>&lt;P&gt;@joydeep741,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xyz |timechart span=1d count by CREATED_DATE 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your CREATED_DATE is continuous, then &lt;CODE&gt;timechart span=1d count&lt;/CODE&gt; also should work&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 06:00:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397027#M115258</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-09T06:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397028#M115259</link>
      <description>&lt;P&gt;@joydeep741 &lt;/P&gt;

&lt;P&gt;Try this Query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Date=mvappend("2018-08-08","2018-08-07","2018-08-04","2018-08-02","2018-08-01")
| mvexpand Date
| table Date
| appendcols  [| gentimes start=08/01/2017 end=09/30/2017 | bin span=1m endtime | stats count by endtime | eval Date=strftime(endtime, "%Y-%m-%d") | table Date     
          | table Date
          ]       
          | eventstats values(Date) as Date          
    | stats count by Date
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Aug 2018 06:49:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397028#M115259</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2018-08-09T06:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397029#M115260</link>
      <description>&lt;P&gt;timechart span=1d count by CREATED_DATE &lt;/P&gt;

&lt;P&gt;This would put created_date as column names in the result...&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 06:51:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397029#M115260</guid>
      <dc:creator>joydeep741</dc:creator>
      <dc:date>2018-08-09T06:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397030#M115261</link>
      <description>&lt;P&gt;@joydeep741 your Created Date as per sample Data seems to be in YYYY-mm-dd format. If you want to use it in timechart, you can try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xyz 
| eval _time=strptime(created_date,"%Y-%m-%d")
| timechart span=1d count
| fillnnull value=0 count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Final fillnull command might not be required. So test without that as well.&lt;BR /&gt;
&lt;CODE&gt;strptime()&lt;/CODE&gt; works based on the String Time Format in your Data. So above is based on sample dates your have provided i.e. &lt;CODE&gt;%Y-%m-%d&lt;/CODE&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 07:03:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397030#M115261</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-09T07:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397031#M115262</link>
      <description>&lt;P&gt;As mentioned ,you could convert _time to the CREATED_DATE as &lt;CODE&gt;CREATED_DATE=strftime(_time,"%Y-%m-%d")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:53:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397031#M115262</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-09-29T20:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397032#M115263</link>
      <description>&lt;P&gt;Awesome man.&lt;/P&gt;

&lt;P&gt;Often the solution to splunk problem statements are the most simplest ones and not Complex queries.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 07:46:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397032#M115263</guid>
      <dc:creator>joydeep741</dc:creator>
      <dc:date>2018-08-09T07:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to add missing values to stats command result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397033#M115264</link>
      <description>&lt;P&gt;True but messing with &lt;CODE&gt;_time&lt;/CODE&gt; is risky &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; If you have a Time Picker input based dashboard you would need to ensure that created_date filter with String Time in YYYY-mm-dd is applied based on earliest and latest time selected in the Time Picker input. &lt;/P&gt;

&lt;P&gt;If _time and created_time are two different time not related to each other, the approach from one of my older answers can be tweaked to do this: &lt;A href="https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html" target="_blank"&gt;https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:49:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-missing-values-to-stats-command-result/m-p/397033#M115264</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T20:49:41Z</dc:date>
    </item>
  </channel>
</rss>

