<?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: Avg function doesn't output any value when used along with &amp;quot;by&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273358#M82390</link>
    <description>&lt;P&gt;@maciep, I'm not in Fast Mode, I'm afraid. &lt;/P&gt;

&lt;P&gt;I can indeed chart any other fields, and even the derived field, unless I use a BY condition. The problem is not the MEDIA_TYPE field, but how splunk reacts when I try to use the BY statement.&lt;/P&gt;

&lt;P&gt;Trying to debug as we speak &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Oct 2015 12:08:40 GMT</pubDate>
    <dc:creator>rjuliani</dc:creator>
    <dc:date>2015-10-19T12:08:40Z</dc:date>
    <item>
      <title>Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273350#M82382</link>
      <description>&lt;P&gt;Hi everyone!&lt;/P&gt;

&lt;P&gt;I'm trying to get some useful stats on my logged data. I have 3 attributes in each log entry, HARVEST_DATE, PUBLISH_DATE and MEDIA_TYPE. I would like to calculate the average difference between PUBLISH_DATE and HARVEST_DATE, as a timestamp (miliseconds).&lt;/P&gt;

&lt;P&gt;To do so, I'm executing the following command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sfmc-ris TYPE=PUSH_POST_ASYNC SUCCESS=true
| eval PUBLISH_DATE_TIMESTAMP=strptime(PUBLISH_DATE, "%Y-%m-%d %H:%M:%S,%3Q") 
| eval HARVEST_DATE_TIMESTAMP=strptime(HARVEST_DATE, "%Y-%m-%d %H:%M:%S,%3Q") 
| eval HARVEST_TO_PUBLISH=round(HARVEST_DATE_TIMESTAMP-PUBLISH_DATE_TIMESTAMP, 1) 
| stats avg(HARVEST_TO_PUBLISH) as HARVEST_PUBLISH_AVG by MEDIA_TYPE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, that outputs &lt;STRONG&gt;no results at all&lt;/STRONG&gt; for HARVEST_PUBLISH_AVG. If I remove the &lt;CODE&gt;by MEDIA_TYPE&lt;/CODE&gt; part, it will show me the average difference without any grouping, no issues.&lt;/P&gt;

&lt;P&gt;Can anyone help me figure out what am I doing wrong? &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:34:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273350#M82382</guid>
      <dc:creator>rjuliani</dc:creator>
      <dc:date>2020-09-29T07:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273351#M82383</link>
      <description>&lt;P&gt;if you remove the stats all together, does your result set have a field called MEDIA_TYPE?  All uppercase with an underscore?   It would seem just off hand that the field doesn't exist, so the by clause is null, so you don't see any results.  &lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 15:50:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273351#M82383</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2015-10-15T15:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273352#M82384</link>
      <description>&lt;P&gt;I agree with MacieP, you must not have a field called "MEDIA_TYPE" in the data pipe to the stats command.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 15:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273352#M82384</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2015-10-15T15:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273353#M82385</link>
      <description>&lt;P&gt;Yes, my result set has MEDIA_TYPE. In fact, If I do a simple count(MEDIA_TYPE) it works fine. other more complex operations with it also work and the results are correct and as expected. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:34:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273353#M82385</guid>
      <dc:creator>rjuliani</dc:creator>
      <dc:date>2020-09-29T07:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273354#M82386</link>
      <description>&lt;P&gt;can you group your results by any other field?  &lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 16:29:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273354#M82386</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2015-10-15T16:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273355#M82387</link>
      <description>&lt;P&gt;If I use any other field, it gives me the same kind of result &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 16:58:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273355#M82387</guid>
      <dc:creator>rjuliani</dc:creator>
      <dc:date>2015-10-15T16:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273356#M82388</link>
      <description>&lt;P&gt;I don't suppose you're in fast mode (instead of say smart mode)?  I mean, from everything else you said I'm guessing not, but thought it worth asking.&lt;/P&gt;

&lt;P&gt;If I were you, I'd start narrowing down where the problem might be.  For example, can you chart/timechart/table other fields.  So is the problem with stats, or any command or a subset of commands etc.&lt;/P&gt;

&lt;P&gt;Also, maybe go back to the beginning of the search after the first pipe and just try to do a stats count by MEDIA_TYPE (or whatever).  Does that work?  If so, add more of the search until it doesn't work again.&lt;/P&gt;

&lt;P&gt;Kind of hard to go through all of those troubleshooting permutations here, but I think you get the idea.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 17:08:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273356#M82388</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2015-10-15T17:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273357#M82389</link>
      <description>&lt;P&gt;Long shot, try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=sfmc-ris TYPE=PUSH_POST_ASYNC SUCCESS=true| eval PUBLISH_DATE_TIMESTAMP=strptime(PUBLISH_DATE, "%Y-%m-%d %H:%M:%S,%3Q") | eval HARVEST_DATE_TIMESTAMP=strptime(HARVEST_DATE, "%Y-%m-%d %H:%M:%S,%3Q") | eval HARVEST_TO_PUBLISH=round(HARVEST_DATE_TIMESTAMP-PUBLISH_DATE_TIMESTAMP, 1) | stats count sum(HARVEST_TO_PUBLISH) as HARVEST_PUBLISH by MEDIA_TYPE | eval HARVEST_PUBLISH_AVG=HARVEST_PUBLISH /count | table MEDIA_TYPE HARVEST_PUBLISH_AVG
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2015 22:14:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273357#M82389</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-10-15T22:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273358#M82390</link>
      <description>&lt;P&gt;@maciep, I'm not in Fast Mode, I'm afraid. &lt;/P&gt;

&lt;P&gt;I can indeed chart any other fields, and even the derived field, unless I use a BY condition. The problem is not the MEDIA_TYPE field, but how splunk reacts when I try to use the BY statement.&lt;/P&gt;

&lt;P&gt;Trying to debug as we speak &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 12:08:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273358#M82390</guid>
      <dc:creator>rjuliani</dc:creator>
      <dc:date>2015-10-19T12:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273359#M82391</link>
      <description>&lt;P&gt;Thanks @somesoni2 for your suggestion. I tried it, along with some variations of the same formula, and nothing. The moment I do "by MEDIA_TYPE" the results get lost and splunk will start showing empty values. &lt;/P&gt;

&lt;P&gt;Any other suggestion is much appreciated! &lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 12:16:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273359#M82391</guid>
      <dc:creator>rjuliani</dc:creator>
      <dc:date>2015-10-19T12:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Avg function doesn't output any value when used along with "by"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273360#M82392</link>
      <description>&lt;P&gt;Although you surely have events for which &lt;CODE&gt;isnotnull(HARVEST_PUBLISH_AVG)&lt;/CODE&gt; is true and also events for which &lt;CODE&gt;isnotnull(MEDIA_TYPE)&lt;/CODE&gt; is true, you must not have any events for which &lt;EM&gt;both&lt;/EM&gt; are true.  You can  join them together with the &lt;CODE&gt;stats&lt;/CODE&gt; command (and also many other commands) if you have another field (e.g. &lt;CODE&gt;host&lt;/CODE&gt; or &lt;CODE&gt;sessionID&lt;/CODE&gt; or &lt;CODE&gt;DOCUMENTID&lt;/CODE&gt;) like this and it should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sfmc-ris TYPE=PUSH_POST_ASYNC SUCCESS=true
| stats values(*) AS * by DOCUMENTID
| eval PUBLISH_DATE_TIMESTAMP=strptime(PUBLISH_DATE, "%Y-%m-%d %H:%M:%S,%3Q") 
| eval HARVEST_DATE_TIMESTAMP=strptime(HARVEST_DATE, "%Y-%m-%d %H:%M:%S,%3Q") 
| eval HARVEST_TO_PUBLISH=round(HARVEST_DATE_TIMESTAMP-PUBLISH_DATE_TIMESTAMP, 1) 
| stats avg(HARVEST_TO_PUBLISH) as HARVEST_PUBLISH_AVG by MEDIA_TYPE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Oct 2015 13:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Avg-function-doesn-t-output-any-value-when-used-along-with-quot/m-p/273360#M82392</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-19T13:40:16Z</dc:date>
    </item>
  </channel>
</rss>

