<?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 Group data by a few factors? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322061#M162512</link>
    <description>&lt;P&gt;Give this a try (assuming no field extraction is done, if it has been, you can ignore the rex commands)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
| rex "id:(?&amp;lt;id&amp;gt;[^\;]+)"
| rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
| stats count by id Pool l
| stats list(count) as count list(Pool) as Pool list(l) as l by id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Mar 2018 19:15:11 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-03-07T19:15:11Z</dc:date>
    <item>
      <title>How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322060#M162511</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I need to prepare statistics of some events occurrences and this is my data in splunk: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07-03-18;11:55:14;id:2222222;&amp;lt;a&amp;gt; f:Pool-A,l:2066;&amp;lt;b&amp;gt; f:Pool-B,l:2066;&amp;lt;c&amp;gt; f:Pool-C,l:959;&amp;lt;d&amp;gt; f:Pool-C,l:454;&amp;lt;e&amp;gt; f:Pool-D,l:959;Stat a:0
07-03-18;11:55:14;id:3333333;&amp;lt;a&amp;gt; f:Pool-A,l:2066;&amp;lt;b&amp;gt; f:Pool-B,l:2066;Stat a:10
07-03-18;11:56:14;id:2222222;Stat a:0
07-03-18;11:56:14;id:2222222;&amp;lt;a&amp;gt; f:Pool-A,l:2066;&amp;lt;b&amp;gt; f:Pool-B,l:2066;Stat a:10
07-03-18;11:56:14;id:3333333;&amp;lt;a&amp;gt; f:Pool-A,l:2066;&amp;lt;b&amp;gt; f:Pool-B,l:2066;Stat a:10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I'd like to display how many times f:Pool-X (where Pool-X could be any string) with the same value of "l:" (for example l:2066) occurs for each node represented by "id".&lt;BR /&gt;
As you can see for given node there may be few f:XXXX values (in different order) or non in one entry. There is a lot of entries for the same nodes.&lt;/P&gt;

&lt;P&gt;This is what I'd like to achieve:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4478iBC686AAD6778359A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;So far I have no idea how to do this. Maybe some of you could help with this not trivial issue.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 15:53:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322060#M162511</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T15:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322061#M162512</link>
      <description>&lt;P&gt;Give this a try (assuming no field extraction is done, if it has been, you can ignore the rex commands)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
| rex "id:(?&amp;lt;id&amp;gt;[^\;]+)"
| rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
| stats count by id Pool l
| stats list(count) as count list(Pool) as Pool list(l) as l by id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 19:15:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322061#M162512</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-07T19:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322062#M162513</link>
      <description>&lt;P&gt;Hi somesoni2, your query is perfect &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; However now I see that this is not exactly what I need. Could you please help again and reorganize this query to group data by the same Pool and l then calculate how many ids belongs to this set. Then display ids with occurrences counter. Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Pool-AA       2066     25       3333333(20), 2222222(5)
               245     10       3333333(4), 4444444(5), 22222222(1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where:&lt;BR /&gt;
- Pool-AA is Pool&lt;BR /&gt;
- 2066 and 245 are l&lt;BR /&gt;
- 25 and 10 are total counter of pair Pool and l&lt;BR /&gt;
- 3333333(20), 2222222(5) - list of ids with number of occurrences&lt;/P&gt;

&lt;P&gt;This query is pretty close to the result I'd like to achieve:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats count by Pool l id
| stats list(count) as count list(id) as ID list(l) as l by Pool
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm totally newbie in splunk so any help or advice are very welcome.&lt;BR /&gt;
Many thanks in advance. I really appreciate your help, &lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 20:40:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322062#M162513</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T20:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322063#M162514</link>
      <description>&lt;P&gt;Try this (first 4 lines are same as previous version, rest are the code to format the output per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
 | rex "id:(?&amp;lt;id&amp;gt;[^\;]+)"
 | rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
 | stats count by id Pool l
 | eval id=id."(".count.")"
 | stats sum(count) as count list(id) as id by Pool l delim="," | nomv id
 | stats list(l) as l list(count) as count list(id) as id by Pool
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can learn more about stats command and available options by using this Splunk documentation page: &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.2/SearchReference/Stats"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.2/SearchReference/Stats&lt;/A&gt;. You can see other command on left side navigation tree. To understand the commands/steps better, add one part at a time to see how it's changing the output.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:02:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322063#M162514</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-07T21:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322064#M162515</link>
      <description>&lt;P&gt;Wow, you are awesome. Your query works like a charm.&lt;BR /&gt;
Many thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322064#M162515</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T21:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322065#M162516</link>
      <description>&lt;P&gt;Do you know if splunk has some limitation for number of displayed data? I see that counter for pair Pool:l shows for example 259 ids but there is 100 ids in id column. Is it expected result? For sure, I took into consideration values from brackets.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:40:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322065#M162516</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T21:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322066#M162517</link>
      <description>&lt;P&gt;The count columns gives total count (e.g. 25 in your example dat) and id column will have all unique ids (e.g 2 in your example data). You're saying you have more unique ids and they are not shown?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:43:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322066#M162517</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-07T21:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322067#M162518</link>
      <description>&lt;P&gt;Yes, I have more unique ids than they are shown. However, I think that this make sense because how to display thousands of data? I didn't mention that I use splunk web search tool not API.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:51:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322067#M162518</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T21:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322068#M162519</link>
      <description>&lt;P&gt;The multivalued command do have limitation of memory usage (see limits.conf specification to more details) which may cause truncation. However, showing 100's of entries in single result row may not be readable anyways. See if you're ok with format of the result with this query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
  | rex "id:(?&amp;lt;id&amp;gt;[^\;]+)"
  | rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
  | stats count by id Pool l
  | eval id=id."(".count.")"
  | stats sum(count) as count list(id) as id by Pool l delim="," | nomv id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 21:56:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322068#M162519</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-03-07T21:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322069#M162520</link>
      <description>&lt;P&gt;Yes, this query is also nice. When you add extra space to delim (e.g delim=", ") then ids are displayed as multi-lines what is really nice. Thanks again for your help. &lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 22:14:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322069#M162520</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-07T22:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322070#M162521</link>
      <description>&lt;P&gt;Unfortunately count is not working as expected. For the following input data it shows that pair Pool-A,l:2066 for id:2222222 occurs only once:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;07-03-18;11:55:14;id:2222222;&amp;lt;a&amp;gt; f:Pool-A,l:2066
07-03-18;11:55:14;id:2222222;&amp;lt;a&amp;gt; f:Pool-A,l:2066;&amp;lt;b&amp;gt; f:Pool-B,l:2066;&amp;lt;c&amp;gt; f:Pool-C,l:959;&amp;lt;d&amp;gt; f:Pool-C,l:454;&amp;lt;e&amp;gt; f:Pool-D,l:959;Stat a:0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It seems that only entries with one pair of f:Pool-A,l:2066 is counted. When more pairs than not counted at all. &lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 10:34:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322070#M162521</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-08T10:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322071#M162522</link>
      <description>&lt;P&gt;My previous thoughts about an issue with count is not correct. It is something wrong with this part: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;running this query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
   | rex "id:(?&amp;lt;id&amp;gt;[^\;]+)"
   | rex max_match=0 "f\:(?&amp;lt;Pool&amp;gt;[^,]+),(?&amp;lt;l&amp;gt;[^\;]+)"
   | table Pool
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results in table with few Pools values and empty rows, but number of Pool-XX is less than expected.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 11:22:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322071#M162522</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-08T11:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Group data by a few factors?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322072#M162523</link>
      <description>&lt;P&gt;I was able to manage my last issue. The solution is to keep Pool and l as one value:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex max_match=0 "f\:(?&amp;lt;Pool_l&amp;gt;[^,]+,l:\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 13:51:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Group-data-by-a-few-factors/m-p/322072#M162523</guid>
      <dc:creator>tatery</dc:creator>
      <dc:date>2018-03-08T13:51:56Z</dc:date>
    </item>
  </channel>
</rss>

