<?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 count the number of each of the different options for a field and present it in a table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244608#M72870</link>
    <description>&lt;P&gt;If you want to format your tables using ASCII, use something like &lt;A href="https://ozh.github.io/ascii-tables/"&gt;https://ozh.github.io/ascii-tables/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2017 17:42:51 GMT</pubDate>
    <dc:creator>sirkgm14vg</dc:creator>
    <dc:date>2017-01-20T17:42:51Z</dc:date>
    <item>
      <title>How do I count the number of each of the different options for a field and present it in a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244606#M72868</link>
      <description>&lt;P&gt;I have an access log from a document system that includes a username and the type of action that was carried out on the document.&lt;BR /&gt;
The documents are all uniquely named and there are thousands of them.&lt;BR /&gt;
There are currently 5 actions a user can carry out on a file (lets call them A, B, C, D and E) and each log entry will include one these.&lt;BR /&gt;
The user can do more than one action be document per day, and the user can do the same action multiple times per day on a single document.&lt;BR /&gt;
All the actions are &lt;BR /&gt;
Want I would like to display on a single line of a table is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;UserName  Total_Docs_Accessed Total_Actions "Number Of Docs With Action A", "Number Of Docs With Action B", "Number Of Docs With Action C" etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some times there will be a ZERO count for some of the actions&lt;/P&gt;

&lt;P&gt;I have been able to get this to work with one line for each action for each user, but that gives up to 5 lines per user, and I have thousands of users. &lt;/P&gt;

&lt;P&gt;I've tried join'ing, eval'ing, stat'ing and nothing seem to work where there is more than one user.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;

&lt;P&gt;Below is a simplified example of the log file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time,          User, File,     Action
01/01/16 10:28 User1 File1.doc A
01/01/16 10:29 User1 File2.doc A
01/01/16 10:30 User1 File2.doc C
01/01/16 10:32 User1 File2.doc B
01/01/16 10:34 User1 File3.doc E
01/01/16 10:35 User1 File1.doc A
01/01/16 10:36 User2 File4.doc A
01/01/16 10:37 User3 File1.doc D
01/01/16 10:38 User4 File5.doc D
01/01/16 10:39 User4 File5.doc A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should give a table thus:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Username, Total Docs,      Total Actions,    Action A, Action B, Action C, Action D, Action E
User1,    3,               6,                3,        1,        1,        0         1
User2,    1,               1,                0,        0,        0,        0,        0         
User3,    1,               1,                0,        0,        0,        1,        0           
User4,    1,               1,                1,        0,        0,        1,        0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2017 10:45:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244606#M72868</guid>
      <dc:creator>capilarity</dc:creator>
      <dc:date>2017-01-20T10:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of each of the different options for a field and present it in a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244607#M72869</link>
      <description>&lt;P&gt;This is one way you can do it. You will use the &lt;CODE&gt;chart&lt;/CODE&gt; command with the class &lt;CODE&gt;over&lt;/CODE&gt; to break out the User by the Action. Then using the &lt;CODE&gt;join&lt;/CODE&gt; command you will do a subsearch which will get the total docs and actions by the user. Append will not work as it will create another set over users in the first column.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="splunk_answers_example_490188.csv"  | chart count(Action)  over User by Action | join [search source="splunk_answers_example_490188.csv"  | stats count(File) as TotalDocs, count(Action) as TotalActions by User]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;=====&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+-------+---+---+---+---+---+--------------+-----------+
| User  | A | B | C | D | E | TotalActions | TotalDocs |
+-------+---+---+---+---+---+--------------+-----------+
| User1 | 3 | 1 | 1 | 0 | 1 |            6 |         6 |
| User2 | 1 | 0 | 0 | 0 | 0 |            1 |         1 |
| User3 | 0 | 0 | 0 | 1 | 0 |            1 |         1 |
| User4 | 1 | 0 | 0 | 1 | 0 |            2 |         2 |
+-------+---+---+---+---+---+--------------+-----------+
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Jan 2017 17:39:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244607#M72869</guid>
      <dc:creator>sirkgm14vg</dc:creator>
      <dc:date>2017-01-20T17:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of each of the different options for a field and present it in a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244608#M72870</link>
      <description>&lt;P&gt;If you want to format your tables using ASCII, use something like &lt;A href="https://ozh.github.io/ascii-tables/"&gt;https://ozh.github.io/ascii-tables/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 17:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244608#M72870</guid>
      <dc:creator>sirkgm14vg</dc:creator>
      <dc:date>2017-01-20T17:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of each of the different options for a field and present it in a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244609#M72871</link>
      <description>&lt;P&gt;Thanks sirkgm14vg. &lt;EM&gt;Almost There!!&lt;/EM&gt; &lt;BR /&gt;
In the above example log file, user 1 accessed only 3 docs but carried out 6 actions overall. It needs some kind of dedup on a per username basis but I can't work out how&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 16:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-each-of-the-different-options-for-a/m-p/244609#M72871</guid>
      <dc:creator>capilarity</dc:creator>
      <dc:date>2017-01-23T16:40:49Z</dc:date>
    </item>
  </channel>
</rss>

