<?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: Stats Sum question in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474047#M133369</link>
    <description>&lt;P&gt;@palisetty what are you trying to do? What is your complete query? Do you get any error or is your output not as expected? What does your data look like and what is the expected output. For the community to assist you better please provide as much details as possible.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jan 2020 13:51:50 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-01-02T13:51:50Z</dc:date>
    <item>
      <title>Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474046#M133368</link>
      <description>&lt;P&gt;I have sum (field) which has been piped into stats sum of another field, Not sure what is happening here. Kindly help me understand.&lt;/P&gt;

&lt;P&gt;sum(field) {| stats sum(sc_bytes) as Bandwidth by s_host}&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474046#M133368</guid>
      <dc:creator>palisetty</dc:creator>
      <dc:date>2020-09-30T03:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474047#M133369</link>
      <description>&lt;P&gt;@palisetty what are you trying to do? What is your complete query? Do you get any error or is your output not as expected? What does your data look like and what is the expected output. For the community to assist you better please provide as much details as possible.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 13:51:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474047#M133369</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-01-02T13:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474048#M133370</link>
      <description>&lt;P&gt;The &lt;CODE&gt;stats&lt;/CODE&gt; command filters fields to only those referenced in the command.  In the case of &lt;CODE&gt;stats sum(field)&lt;/CODE&gt; the only field available to later commands is &lt;CODE&gt;sum(fields)&lt;/CODE&gt;.  The &lt;CODE&gt;sc_bytes&lt;/CODE&gt; and &lt;CODE&gt;s_host&lt;/CODE&gt; fields are removed (as are all others).   Consider using &lt;CODE&gt;eventstats&lt;/CODE&gt;, instead.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 13:55:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474048#M133370</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-01-02T13:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474049#M133371</link>
      <description>&lt;P&gt;I am sorry for the discomfort. Actually, I got that bit from Quizlet. Let us take the proper query, I have an issue with multiple stats functions within a Search Component. I don't understand what is going on.&lt;/P&gt;

&lt;P&gt;index=main sourcetype=access_combined_wcookie | stats values(useragent) as "Agents used" count as "Times used" by useragent&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:30:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474049#M133371</guid>
      <dc:creator>palisetty</dc:creator>
      <dc:date>2020-09-30T03:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474050#M133372</link>
      <description>&lt;P&gt;Not exactly true; there is also the &lt;CODE&gt;BY&lt;/CODE&gt; field, namely &lt;CODE&gt;userAgent&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 15:22:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474050#M133372</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-02T15:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474051#M133373</link>
      <description>&lt;P&gt;The search is idiotic, as is any search of thts format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats anyfunc(byField) BY byField
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jan 2020 15:24:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474051#M133373</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-02T15:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474052#M133374</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt; &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1406"&gt;@woodcock&lt;/a&gt; &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt; &lt;BR /&gt;
I am sorry for the discomfort. Actually, I got that bit from Quizlet. &lt;/P&gt;

&lt;P&gt;Let us take the proper query, I have an issue with multiple stats functions within a Search Component. I don't understand what is going on.&lt;/P&gt;

&lt;P&gt;index=main sourcetype=access_combined_wcookie | stats values(useragent) as "Agents used" count as "Times used" by useragent&lt;/P&gt;

&lt;P&gt;I have rewritten it so that everyone can see it. &lt;STRONG&gt;I don't want to use eval command as I have no idea about it.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:30:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474052#M133374</guid>
      <dc:creator>palisetty</dc:creator>
      <dc:date>2020-09-30T03:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Stats Sum question</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474053#M133375</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/32936"&gt;@palisetty&lt;/a&gt; if you are preparing for any Splunk Certification exam, I would recommend you to go through the course content and refer to Splunk Documentation for all your queries, understanding and additional reading. Splunk Docs have all the required examples and explanations which you require for Certification and in fact for actual development usage.&lt;/P&gt;

&lt;P&gt;In my opinion quizlet is a inappropriate way to learn Splunk as it gives questions based on memory and half baked scenarios which may actually be incorrect. Learning from such source will lead to incomplete and incorrect knowledge which would be disastrous.&lt;/P&gt;

&lt;P&gt;So coming to your follow up details, seems like you are interested in multiple aggregations within stats command. &lt;/P&gt;

&lt;P&gt;If you are going through stats command you should refer to documentation for the same as well to understand it in depth: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Stats" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Stats&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You can also refer to Splunk Documentation for all the available/applicable aggregation functions here: &lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Aggregatefunctions" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Aggregatefunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Best way to learn through these examples is to try them out using Splunk's _internal index data on local machine or ingest Splunk's tutorial data as mentioned in the Fundamental course as well as on Splunk Documentation for Search Tutorial: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchTutorial/GetthetutorialdataintoSplunk" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchTutorial/GetthetutorialdataintoSplunk&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;In your question the example has been created based on same tutorial data where data has been uploaded to main (default) index with default sourcetype (pre-defined) access_combined_wcookie. (explained in Search documentation: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchTutorial/Aboutthetutorialdata" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchTutorial/Aboutthetutorialdata&lt;/A&gt;)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=access_combined_wcookie 
| stats values(useragent) as "Agents used" count as "Times used" by useragent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the above stats function &lt;CODE&gt;by useragent&lt;/CODE&gt; defines the key field for aggregation i.e. each row in the result of stats function will have unique value for each useragent present.&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;values()&lt;/CODE&gt; stats aggregation function gives unique values of specific field. Which implies you will have two columns &lt;CODE&gt;useragent&lt;/CODE&gt; and &lt;CODE&gt;Agents used&lt;/CODE&gt; with same values as both are unique per row. So, your SPL seems to be performing stats (transformation) for a non-realistic scenario.&lt;/P&gt;

&lt;P&gt;Coming to my point, if your &lt;CODE&gt;use case is to get the access count through various user agents&lt;/CODE&gt;, you could have performed the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=access_combined_wcookie
| stats count as "Times used" by useragent
| rename useragent as "Agents used"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:35:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-Sum-question/m-p/474053#M133375</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-30T03:35:02Z</dc:date>
    </item>
  </channel>
</rss>

