<?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 count unique events pr class in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445256#M171582</link>
    <description>&lt;P&gt;Thanks for you reply.   First one is close, but I would like to group it together.&lt;BR /&gt;
Last one only counts number of colors, ignoring the number of cars in  each color pr car group.&lt;/P&gt;

&lt;P&gt;Your first result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;car color   count
BMW black   1
Ford    blue    1
Ford    green   1
Opel    blue    1
Opel    green   1
Opel    yellow  2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you look at my request, I would like one multivalue Opel with list of colors and the number of cars in each color.&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 07:10:25 GMT</pubDate>
    <dc:creator>lakromani</dc:creator>
    <dc:date>2019-05-02T07:10:25Z</dc:date>
    <item>
      <title>How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445254#M171580</link>
      <description>&lt;P&gt;I need help with &lt;STRONG&gt;stats&lt;/STRONG&gt; in Splunk&lt;/P&gt;

&lt;P&gt;Let's say you have these example data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval car="Opel" | eval color="green"
| append [| stats count | eval car="Ford" | eval color="blue"]
| append [| stats count | eval car="Opel" | eval color="yellow"]
| append [| stats count | eval car="BMW" | eval color="black"]
| append [| stats count | eval car="Opel" | eval color="yellow"]
| append [| stats count | eval car="Ford" | eval color="green"]
| append [| stats count | eval car="Opel" | eval color="blue"]
| fields - count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Running it gives this table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*car*   *color*
Opel    green
Ford    blue
Opel    yellow
BMW black
Opel    yellow
Ford    green
Opel    blue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to create a table that counts number of car in each color pr each car type.&lt;/P&gt;

&lt;P&gt;This is close, but not correct (it counts total cars and list the different colors)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval car="Opel" | eval color="green"
| append [| stats count | eval car="Ford" | eval color="blue"]
| append [| stats count | eval car="Opel" | eval color="yellow"]
| append [| stats count | eval car="BMW" | eval color="black"]
| append [| stats count | eval car="Opel" | eval color="yellow"]
| append [| stats count | eval car="Ford" | eval color="green"]
| append [| stats count | eval car="Opel" | eval color="blue"]
| fields - count
| stats count values(color) by car

car count   values(color)
BMW 1   black
Ford    2   blue
            green
Opel    4   blue
            green
            yellow
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is how I would like the output to be: (count number of car pr color pr each car type&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;car count   values(color)
BMW 1   black
Ford    1   blue
        1   green
Opel    1   blue
        1   green
        2   yellow
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 06:53:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445254#M171580</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2019-05-02T06:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445255#M171581</link>
      <description>&lt;P&gt;Hi @lakromani,&lt;/P&gt;

&lt;P&gt;What you're looking for is a       &lt;CODE&gt;...| stats count by car, color&lt;/CODE&gt; with some magic.&lt;/P&gt;

&lt;P&gt;This should do the trick, let me know if it works out for you :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval car="Opel" | eval color="green"
  | append [| stats count | eval car="Ford" | eval color="blue"]
  | append [| stats count | eval car="Opel" | eval color="yellow"]
  | append [| stats count | eval car="BMW" | eval color="black"]
  | append [| stats count | eval car="Opel" | eval color="yellow"]
  | append [| stats count | eval car="Ford" | eval color="green"]
  | append [| stats count | eval car="Opel" | eval color="blue"]
  | stats count by car, color
  | sort -count
  |stats list(color) as color list(count) as count by car
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 06:58:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445255#M171581</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T06:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445256#M171582</link>
      <description>&lt;P&gt;Thanks for you reply.   First one is close, but I would like to group it together.&lt;BR /&gt;
Last one only counts number of colors, ignoring the number of cars in  each color pr car group.&lt;/P&gt;

&lt;P&gt;Your first result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;car color   count
BMW black   1
Ford    blue    1
Ford    green   1
Opel    blue    1
Opel    green   1
Opel    yellow  2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you look at my request, I would like one multivalue Opel with list of colors and the number of cars in each color.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445256#M171582</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2019-05-02T07:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445257#M171583</link>
      <description>&lt;P&gt;From your answer I did make this workaround.  Not the best.&lt;BR /&gt;
Can not this be done in stats directly?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by car, color
| eval info=color.":".count
| stats values(info) by car

car values(info)
BMW black:1
Ford    blue:1
        green:1
Opel    blue:1
        green:1
        yellow:2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 07:14:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445257#M171583</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2019-05-02T07:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445258#M171584</link>
      <description>&lt;P&gt;I edited my answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; try again with the new query above &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:18:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445258#M171584</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T07:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445259#M171585</link>
      <description>&lt;P&gt;Ahh, did work perfectly, thanks.&lt;BR /&gt;
Accepted &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:26:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445259#M171585</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2019-05-02T07:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445260#M171586</link>
      <description>&lt;P&gt;Just a side note, there is &lt;CODE&gt;| makeresults&lt;/CODE&gt; for when you want to create an event without any data. It's better than &lt;CODE&gt;stats&lt;/CODE&gt; because it can run directly on the search head. It's also got a &lt;CODE&gt;count&lt;/CODE&gt; attribute for when you need more than one event, check the docs &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Makeresults"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:32:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445260#M171586</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2019-05-02T07:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445261#M171587</link>
      <description>&lt;P&gt;I know about the &lt;CODE&gt;makeresult&lt;/CODE&gt;, but did not find any solution on how to add cars and colors.  Can you give me a hint?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 07:57:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445261#M171587</guid>
      <dc:creator>lakromani</dc:creator>
      <dc:date>2019-05-02T07:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique events pr class</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445262#M171588</link>
      <description>&lt;P&gt;it's actually pretty easy, similar to what you did but with &lt;CODE&gt;makeresults&lt;/CODE&gt; instead of &lt;CODE&gt;|stats count&lt;/CODE&gt; :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults  | eval car="Opel" | eval color="green"
   | append [| makeresults | eval car="Ford" | eval color="blue"]
   | append [| makeresults | eval car="Opel" | eval color="yellow"]
   | append [| makeresults | eval car="BMW" | eval color="black"]
   | append [| makeresults | eval car="Opel" | eval color="yellow"]
   | append [| makeresults | eval car="Ford" | eval color="green"]
   | append [|makeresults  | eval car="Opel" | eval color="blue"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 08:01:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-unique-events-pr-class/m-p/445262#M171588</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-02T08:01:36Z</dc:date>
    </item>
  </channel>
</rss>

