<?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: Can I get a count of distinct values in multivalue field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59492#M14652</link>
    <description>&lt;P&gt;You are brilliant!  Thank you, this is exactly what we are looking for.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2013 16:52:42 GMT</pubDate>
    <dc:creator>hulahoop</dc:creator>
    <dc:date>2013-03-13T16:52:42Z</dc:date>
    <item>
      <title>Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59488#M14648</link>
      <description>&lt;P&gt;What I'm looking for is a hybrid of the stats list() and values() functions.  First, I'd like the list of unique values for a multivalue field, then alongside each unique value, I'd like the count of occurrences of that value.  Is this possible?&lt;/P&gt;

&lt;P&gt;Maybe this is better illustrated through an example.&lt;/P&gt;

&lt;P&gt;Given a set of events like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;03/12/2013 15:55:00 id=foo abc=123,123,123
03/12/2013 15:56:00 id=bar abc=123,456,789,789
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can get tables like these with the list() and values() functions, respectively:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  id     abc               id     abc
----------------         ----------------
 foo     123              foo     123
         123              bar     123
         123                      456
 bar     123                      789
         456
         789
         789
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But what I really want is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  id     abc    
----------------
 foo     123 (3)
 bar     123 (1)
         456 (1)
         789 (2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I believe this to be possible... for a search query superhero (which I am not).  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2013 23:49:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59488#M14648</guid>
      <dc:creator>hulahoop</dc:creator>
      <dc:date>2013-03-12T23:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59489#M14649</link>
      <description>&lt;P&gt;I tried doing this yesterday, had some trouble.  You definitely want to use values().  I know we covered this in architect bootcamp training, but I forget how the instructor did it.  You can always do a calculated field and convert the number to a string, but if you want a true column of (NUMERIC) counts, that's where i got lost... &lt;/P&gt;

&lt;P&gt;i'll wait patiently for that answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2013 00:05:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59489#M14649</guid>
      <dc:creator>dwaynehoover</dc:creator>
      <dc:date>2013-03-13T00:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59490#M14650</link>
      <description>&lt;P&gt;I was able to get the information desired, but not really in the clean format provided by the values() or list() functions using this approach:&lt;/P&gt;

&lt;P&gt;... | stats list(abc) as tokens by id | mvexpand tokens | stats count by id,tokens | mvcombine tokens&lt;/P&gt;

&lt;P&gt;id   tokens   count&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;bar    123       1&lt;BR /&gt;
         456&lt;BR /&gt;
bar    789       2&lt;BR /&gt;
foo    123       3&lt;/P&gt;

&lt;P&gt;The output is a table of id, tokens and count, grouped by count.  This technically answers the question, but not in a user-friendly format.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2013 00:10:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59490#M14650</guid>
      <dc:creator>hulahoop</dc:creator>
      <dc:date>2013-03-13T00:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59491#M14651</link>
      <description>&lt;P&gt;Try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... 
| table id abc def ghi
| untable id field value 
| makemv delim="," value
| mvexpand value
| stats count by id field value
| eval pair=value." (".count.")"
| stats list(pair) as values by id field
| xyseries id field values
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Given :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;03/12/2013 15:55:00 id=foo abc=123,123,123 def=345,567,678,890,890
03/12/2013 15:56:00 id=bar abc=123,456,789,789 def=345,345,345,789,789
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/mash_1.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2013 08:44:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59491#M14651</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-13T08:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59492#M14652</link>
      <description>&lt;P&gt;You are brilliant!  Thank you, this is exactly what we are looking for.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2013 16:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59492#M14652</guid>
      <dc:creator>hulahoop</dc:creator>
      <dc:date>2013-03-13T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59493#M14653</link>
      <description>&lt;P&gt;shucks.&lt;BR /&gt;
For some reason I couldnt get this to work - &lt;BR /&gt;
&lt;CODE&gt;... | extract auto=f pairdelim=" " kvdelim="="&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Might just be me though.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2013 17:49:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59493#M14653</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-13T17:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59494#M14654</link>
      <description>&lt;P&gt;For anyone who wants to verify (or learn from) this query. You can do &lt;CODE&gt;source="/path/to/the/log"&lt;BR /&gt;
| rex field=_raw "abc=(?&amp;lt;abc&amp;gt;\S+) def=(?&amp;lt;def&amp;gt;\S+)"&lt;/CODE&gt; to extract the &lt;CODE&gt;abc&lt;/CODE&gt; and &lt;CODE&gt;def&lt;/CODE&gt; fields properly (otherwise Splunk will only extract the first value of the comma-delimited list).&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 21:06:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59494#M14654</guid>
      <dc:creator>hobbes3</dc:creator>
      <dc:date>2013-07-25T21:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can I get a count of distinct values in multivalue field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59495#M14655</link>
      <description>&lt;P&gt;Try this method.&lt;/P&gt;

&lt;P&gt;This replicates your data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="foo;123,123,123:bar;123,456,789,789"
| makemv data delim=":" 
| mvexpand data 
| makemv data delim=";" 
| eval id=mvindex(data,0), abc=mvindex(data,1)
| makemv abc delim="," 
| table id, abc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gets the results you're looking for. if you already have the data in separate events, only the last two lines are needed.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="foo;123,123,123:bar;123,456,789,789"
| makemv data delim=":" 
| mvexpand data 
| makemv data delim=";" 
| eval id=mvindex(data,0), abc=mvindex(data,1)
| makemv abc delim="," 
| stats count(eval(mvcount(abc))) as count by id, abc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jun 2019 22:30:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-get-a-count-of-distinct-values-in-multivalue-field/m-p/59495#M14655</guid>
      <dc:creator>dkadavis</dc:creator>
      <dc:date>2019-06-26T22:30:15Z</dc:date>
    </item>
  </channel>
</rss>

