<?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 do I group two fields (multivalued)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388368#M113238</link>
    <description>&lt;P&gt;I changed the "mvsplit" to "split" in the second eval.&lt;/P&gt;

&lt;P&gt;It works perfect that way! Thanks a lot!&lt;/P&gt;</description>
    <pubDate>Thu, 14 Feb 2019 15:28:48 GMT</pubDate>
    <dc:creator>philippbloch</dc:creator>
    <dc:date>2019-02-14T15:28:48Z</dc:date>
    <item>
      <title>How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388364#M113234</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have the following table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;User           Group
-------------  -------------
User_A         Group_A
-------------  -------------
User_A         Group_B
-------------  -------------
User_A         Group_C
-------------  -------------
User_B         Group_A
-------------  -------------
User_B         Group_B
-------------  -------------
User_B         Group_C
-------------  -------------
User_C         Group_C
-------------  -------------
User_D         Group_D
-------------  -------------
User_D         Group_E
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which I want to group as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;User           Group
-------------  -------------
User_A         Group_A
User_B         Group_B
               Group_C
-------------  -------------
User_C         Group_C
-------------  -------------
User_D         Group_D
               Group_E
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;my results&amp;gt; | stats values(Group) as Group by User | stats values(User) as User by Group
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions how to achieve this?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
-Philipp&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 13:45:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388364#M113234</guid>
      <dc:creator>philippbloch</dc:creator>
      <dc:date>2019-02-14T13:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388365#M113235</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;just | stats values(Group) as Group by User should be enough
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 14:24:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388365#M113235</guid>
      <dc:creator>saurabhkharkar</dc:creator>
      <dc:date>2019-02-14T14:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388366#M113236</link>
      <description>&lt;P&gt;Your attempt is close, but you need to apply a little trick to let the second stats work (as the "by Group" won't have the desired effect when Group is a multi valued field). So you first need turn Group into a single valued field, then do the second stats and then split Group out again. Since values() returns a sorted result, this should work and result in the same concatenated strings for users that have the same set of groups.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;my results&amp;gt;
| stats values(Group) as Group by User
| eval Group=mvjoin(Group,"|")
| stats values(User) as User by Group
| eval Group=split(Group,"|")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This has the following intermediate results:&lt;/P&gt;

&lt;P&gt;After the first stats and eval:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; User           Group
 -------------  -------------
 User_A         Group_A|Group_B|Group_C
  -------------  -------------
 User_B         Group_A|Group_B|Group_C
 -------------  -------------
 User_C         Group_C
 -------------  -------------
 User_D         Group_D|Group_E
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After the second stats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; User           Group
 -------------  -------------
 User_A         Group_A|Group_B|Group_C
 User_B         
 -------------  -------------
 User_C         Group_C
 -------------  -------------
 User_D         Group_D|Group_E
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After the second eval:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; User           Group
 -------------  -------------
 User_A         Group_A
 User_B         Group_B
                Group_C
 -------------  -------------
 User_C         Group_C
 -------------  -------------
 User_D         Group_D
                Group_E
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2019 14:30:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388366#M113236</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-02-14T14:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388367#M113237</link>
      <description>&lt;P&gt;No it isn't, as that doesn't group the user field into a multi valued field for users that have the same set of groups.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 14:32:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388367#M113237</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-02-14T14:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388368#M113238</link>
      <description>&lt;P&gt;I changed the "mvsplit" to "split" in the second eval.&lt;/P&gt;

&lt;P&gt;It works perfect that way! Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 15:28:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388368#M113238</guid>
      <dc:creator>philippbloch</dc:creator>
      <dc:date>2019-02-14T15:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group two fields (multivalued)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388369#M113239</link>
      <description>&lt;P&gt;You're welcome! And indeed, it should be split not mvsplit, my bad. I've corrected that in my answer as well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 15:36:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-group-two-fields-multivalued/m-p/388369#M113239</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-02-14T15:36:02Z</dc:date>
    </item>
  </channel>
</rss>

