<?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 use 'group by' with two fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115654#M30673</link>
    <description>&lt;P&gt;It sounds like you need a nested &lt;CODE&gt;stats&lt;/CODE&gt;, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by book location
| sort count 
| stats list(book), list(count) by location
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H4&gt;Breaking down the search&lt;/H4&gt;

&lt;OL&gt;
&lt;LI&gt;Get a count of books by location &lt;CODE&gt;| stats count by book location&lt;/CODE&gt;, so now we have the values. &lt;/LI&gt;
&lt;LI&gt;Then we sort by ascending count of books &lt;CODE&gt;| sort count&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Lastly, we list the book titles, then the count values separately &lt;STRONG&gt;by location&lt;/STRONG&gt; &lt;CODE&gt;|stats list(book), list(count) by location&lt;/CODE&gt; &lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 12 Nov 2014 17:15:09 GMT</pubDate>
    <dc:creator>aljohnson_splun</dc:creator>
    <dc:date>2014-11-12T17:15:09Z</dc:date>
    <item>
      <title>How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115649#M30668</link>
      <description>&lt;P&gt;I have 5 books. I have to show the count of these 5 books for different location.&lt;BR /&gt;
I am getting the report like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location             Book           Count
-------------      --------       ----------
NYC                  Book1            3
NYC                  Book2            5
.
.
.
Boston               Book1            22
Boston               Book2            99
.
.
Dallas               Book1            44
.
.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have to generate report like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location             Book           Count
-------------      --------       ----------
NYC                  Book1            3
-----                Book2            5
-----                Book3            3
-----                Book4            1
-----                Book5            8

Boston               Book1            32
-----                Book2            51
-----                Book3            32
-----                Book4            11
-----                Book5            88

Dallas               Book1            13
-----                Book2            15
-----                Book3            13
-----                Book4            11
-----                Book5            18
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can anyone help me with the query??&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2014 15:17:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115649#M30668</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2014-11-11T15:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115650#M30669</link>
      <description>&lt;P&gt;Can anyone help me???? &lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 14:16:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115650#M30669</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2014-11-12T14:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115651#M30670</link>
      <description>&lt;P&gt;I'm not sure I understand the question. I don't see a difference between the two reports except that the top one has fewer entries. What exactly is the difference that you are trying to accomplish?&lt;/P&gt;

&lt;P&gt;Also, what is the search you are using to generate the top table?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 15:01:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115651#M30670</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-11-12T15:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115652#M30671</link>
      <description>&lt;P&gt;In the first report,&lt;BR /&gt;
NYC                  Book1            3&lt;BR /&gt;
NYC                  Book2            5&lt;/P&gt;

&lt;P&gt;NYC are repeated in each row.I want report in which location are not repeated.&lt;BR /&gt;
i used query as eval count as ABC by location,Book&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 15:23:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115652#M30671</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2014-11-12T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115653#M30672</link>
      <description>&lt;P&gt;That's not a valid search. I would have expected &lt;CODE&gt;stats count as ABC by location, Book&lt;/CODE&gt;. And that search would return a column &lt;CODE&gt;ABC&lt;/CODE&gt;, not &lt;CODE&gt;Count&lt;/CODE&gt; as you've shown here.&lt;/P&gt;

&lt;P&gt;Anyways, my best guess is that it will be difficult to do exactly what you're asking. You really shouldn't expend a lot of effort trying to make the search language change the presentation of tables. Presentation is what charts are for!&lt;/P&gt;

&lt;P&gt;If you change your search to &lt;CODE&gt;chart count by location, Book&lt;/CODE&gt; you'll get a result where one of each location is in the first column, plus one column for each book with the appropriate count. If you're just trying to compress the presentation, that might help.&lt;/P&gt;

&lt;P&gt;Plus, you can easily turn this into a column or bar chart.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Nov 2014 16:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115653#M30672</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-11-12T16:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115654#M30673</link>
      <description>&lt;P&gt;It sounds like you need a nested &lt;CODE&gt;stats&lt;/CODE&gt;, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by book location
| sort count 
| stats list(book), list(count) by location
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H4&gt;Breaking down the search&lt;/H4&gt;

&lt;OL&gt;
&lt;LI&gt;Get a count of books by location &lt;CODE&gt;| stats count by book location&lt;/CODE&gt;, so now we have the values. &lt;/LI&gt;
&lt;LI&gt;Then we sort by ascending count of books &lt;CODE&gt;| sort count&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Lastly, we list the book titles, then the count values separately &lt;STRONG&gt;by location&lt;/STRONG&gt; &lt;CODE&gt;|stats list(book), list(count) by location&lt;/CODE&gt; &lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 12 Nov 2014 17:15:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115654#M30673</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2014-11-12T17:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115655#M30674</link>
      <description>&lt;P&gt;it worked, Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2014 09:41:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115655#M30674</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2014-11-13T09:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115656#M30675</link>
      <description>&lt;P&gt;Thanks AlJohnson. It worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This answer also helped me..&lt;BR /&gt;
(&lt;A href="http://answers.splunk.com/answers/73898/removing-duplicates-in-exported-report-results.html"&gt;http://answers.splunk.com/answers/73898/removing-duplicates-in-exported-report-results.html&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 13 Nov 2014 14:45:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115656#M30675</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2014-11-13T14:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'group by' with two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115657#M30676</link>
      <description>&lt;P&gt;Thank you to much! I was useful for me too! but one question more: for each "Location", how i can get the "Book" with max "count"? Ex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Location       Book       Count
-------------  --------   ----------
 NYC            Book5       3
 Boston         Book5       32
 Dallas         Book5       13
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jul 2017 16:22:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-group-by-with-two-fields/m-p/115657#M30676</guid>
      <dc:creator>alcastic</dc:creator>
      <dc:date>2017-07-18T16:22:13Z</dc:date>
    </item>
  </channel>
</rss>

