<?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 get the count of unique values for a field per event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214173#M62819</link>
    <description>&lt;P&gt;That is perfect javiergn. Exactly what I was looking to do. Cheers.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2016 09:14:57 GMT</pubDate>
    <dc:creator>Aaron_Fogarty</dc:creator>
    <dc:date>2016-04-26T09:14:57Z</dc:date>
    <item>
      <title>How to get the count of unique values for a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214171#M62817</link>
      <description>&lt;P&gt;I have a field named &lt;STRONG&gt;Visit&lt;/STRONG&gt; that can have several vales: "Order Entry", "Order Reference" and 5 others. I want to count every Visit per event only once per value.&lt;/P&gt;

&lt;P&gt;What I mean by this is that in Example one, the Visit count for this event will be only 1&lt;BR /&gt;
and in Example two, the Visit count for the event will be 2.&lt;/P&gt;

&lt;P&gt;Event Example one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Client - User:123 - Visit="Order Entry" - Apr 25, 2016, 9:34:58 AM EDT
Client - User:123 - New selection begin  - Apr 25, 2016, 9:34:58 AM EDT
Client - User:123 - New selection begin  - Apr 25, 2016, 9:34:58 AM EDT
Client - User:123 - Loading selection begin  - Apr 25, 2016, 9:34:58 AM EDT
Client - User:123 - Visit="Order Entry" - Apr 25, 2016, 9:34:58 AM EDT
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Event Example two: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Client - User:456 - Visit="Order Entry" - Apr 25, 2016, 6:46:22 AM EDT
Client - User:456 - New order begin  - Apr 25, 2016, 6:46:22 AM EDT
Client - User:456 - Visit="Order Reference" - Apr 25, 2016, 6:46:22 AM EDT
Client - User:456 - Successful login.  Failed login attempts 0.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:15:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214171#M62817</guid>
      <dc:creator>Aaron_Fogarty</dc:creator>
      <dc:date>2016-04-25T16:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of unique values for a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214172#M62818</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;If your events are separated as you described above, you can try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search here
| rex max_match=0 "Visit=(?&amp;lt;visits&amp;gt;\"[^\"]+\")"
| mvexpand visits
| stats values(visits) as visits dc(visits) as visit_counts by _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count
| eval _raw = "
 Client - User:123 - Visit=\"Order Entry\" - Apr 25, 2016, 9:34:58 AM EDT
 Client - User:123 - New selection begin  - Apr 25, 2016, 9:34:58 AM EDT
 Client - User:123 - New selection begin  - Apr 25, 2016, 9:34:58 AM EDT
 Client - User:123 - Loading selection begin  - Apr 25, 2016, 9:34:58 AM EDT
 Client - User:123 - Visit=\"Order Entry\" - Apr 25, 2016, 9:34:58 AM EDT
"
| rex max_match=0 "Visit=(?&amp;lt;visits&amp;gt;\"[^\"]+\")"
| mvexpand visits
| stats values(visits) as visits dc(visits) as visit_counts by _raw

# visit_counts = 1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count
| eval _raw = "
 Client - User:456 - Visit=\"Order Entry\" - Apr 25, 2016, 6:46:22 AM EDT
 Client - User:456 - New order begin  - Apr 25, 2016, 6:46:22 AM EDT
 Client - User:456 - Visit=\"Order Reference\" - Apr 25, 2016, 6:46:22 AM EDT
 Client - User:456 - Successful login.  Failed login attempts 0.
"
| rex max_match=0 "Visit=(?&amp;lt;visits&amp;gt;\"[^\"]+\")"
| mvexpand visits
| stats values(visits) as visits dc(visits) as visit_counts by _raw


# visit_counts = 2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 17:11:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214172#M62818</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-04-25T17:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the count of unique values for a field per event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214173#M62819</link>
      <description>&lt;P&gt;That is perfect javiergn. Exactly what I was looking to do. Cheers.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 09:14:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-count-of-unique-values-for-a-field-per-event/m-p/214173#M62819</guid>
      <dc:creator>Aaron_Fogarty</dc:creator>
      <dc:date>2016-04-26T09:14:57Z</dc:date>
    </item>
  </channel>
</rss>

